Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: focus issue in filterable multiselect #16840

Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,6 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect<
return changes;
case InputBlur:
case InputKeyDownEscape:
setInputFocused(false);
setInputValue('');
setIsOpen(false);
return changes;
case FunctionToggleMenu:
Expand Down Expand Up @@ -714,6 +712,11 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect<
}
},
onFocus: () => setInputFocused(true),
onBlur: () => {
!isOpen && setInputFocused(false);
setInputValue('');
// setIsOpen(false);
tay1orjones marked this conversation as resolved.
Show resolved Hide resolved
},
})
);
const menuProps = getMenuProps({}, { suppressRefError: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ describe('FilterableMultiSelect', () => {
expect(screen.getByPlaceholderText('test')).toHaveDisplayValue(3);
});

it('should clear input value when clicking on cross button', async () => {
render(<FilterableMultiSelect {...mockProps} placeholder="test" />);
await openMenu();

await userEvent.type(screen.getByPlaceholderText('test'), '3');

const clearButton = screen.getByRole('button', {
name: 'Clear selected item',
});
await userEvent.click(clearButton);

expect(screen.getByPlaceholderText('test')).toHaveDisplayValue('');
});

it('should respect slug prop', async () => {
const { container } = render(
<FilterableMultiSelect {...mockProps} slug={<Slug />} />
Expand Down
Loading