Skip to content

Commit

Permalink
fix: focus issue in filterable multiselect (#16840)
Browse files Browse the repository at this point in the history
* fix: focus issue in filterable multiselect

* fix: added test cases and focus fixes

* Update FilterableMultiSelect-test.js

* Update FilterableMultiSelect-test.js

* Update MultiSelect.stories.js

* Update packages/react/src/components/MultiSelect/FilterableMultiSelect.tsx

---------

Co-authored-by: Taylor Jones <tay1orjones@users.noreply.github.com>
  • Loading branch information
riddhybansal and tay1orjones committed Jun 26, 2024
1 parent 1190e09 commit 3636b9f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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,10 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect<
}
},
onFocus: () => setInputFocused(true),
onBlur: () => {
!isOpen && setInputFocused(false);
setInputValue('');
},
})
);
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

0 comments on commit 3636b9f

Please sign in to comment.