fix(select): ensure filter dropdown matches input field width (#38886)

This commit is contained in:
Enzo Martellucci
2026-03-30 15:52:37 +02:00
committed by GitHub
parent 89f7e5e7ba
commit 41d401a879
2 changed files with 33 additions and 1 deletions

View File

@@ -915,6 +915,38 @@ test('"Select all" does not affect disabled options', async () => {
expect(await findSelectValue()).not.toHaveTextContent(options[1].label);
});
test('dropdown takes full width of the select input for multi select', async () => {
render(
<div style={{ width: '400px' }}>
<Select {...defaultProps} mode="multiple" options={OPTIONS} />
</div>,
);
await open();
const dropdown = document.querySelector(
'.ant-select-dropdown',
) as HTMLElement;
expect(dropdown).toBeInTheDocument();
// When popupMatchSelectWidth is true, antd dynamically matches the
// trigger width and does not set a fixed inline width on the dropdown.
const widthValue = parseInt(dropdown.style.width, 10);
expect(Number.isNaN(widthValue) || widthValue === 0).toBe(true);
});
test('dropdown takes full width of the select input for single select', async () => {
render(
<div style={{ width: '400px' }}>
<Select {...defaultProps} mode="single" options={OPTIONS} />
</div>,
);
await open();
const dropdown = document.querySelector(
'.ant-select-dropdown',
) as HTMLElement;
expect(dropdown).toBeInTheDocument();
const widthValue = parseInt(dropdown.style.width, 10);
expect(Number.isNaN(widthValue) || widthValue === 0).toBe(true);
});
test('does not fire onChange when searching but no selection', async () => {
const onChange = jest.fn();
render(

View File

@@ -777,7 +777,7 @@ const Select = forwardRef(
options={visibleOptions}
optionRender={option => <Space>{option.label || option.value}</Space>}
oneLine={oneLine}
popupMatchSelectWidth={selectAllEnabled ? 168 : true}
popupMatchSelectWidth
css={props.css}
dropdownAlign={DROPDOWN_ALIGN_BOTTOM}
{...props}