Skip to content

Commit

Permalink
fix: react-combobox should close on blur after clicking expand icon (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
smhigley authored and Hotell committed Feb 9, 2023
1 parent 7820de8 commit f919dac
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "fix: Combobox should close on blur after clicking expand icon",
"packageName": "@fluentui/react-combobox",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@ describe('Combobox', () => {
expect(queryByRole('listbox')).toBeNull();
});

it('closes the popup on blur/outside click after clicking on the expand icon', () => {
const { getByTestId, queryByRole } = render(
<>
<Combobox expandIcon={{ 'data-testid': 'icon' } as React.HTMLAttributes<HTMLSpanElement>}>
<Option>Red</Option>
<Option>Green</Option>
<Option>Blue</Option>
</Combobox>
<div data-testid="outside">outside</div>
</>,
);

userEvent.click(getByTestId('icon'));
expect(queryByRole('listbox')).not.toBeNull();

userEvent.click(getByTestId('outside'));
expect(queryByRole('listbox')).toBeNull();
});

it('does not close the combobox on click with controlled open', () => {
const { getByRole } = render(
<Combobox open>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ export const useCombobox_unstable = (props: ComboboxProps, ref: React.Ref<HTMLIn
const { onMouseDown: onIconMouseDown, onClick: onIconClick } = state.expandIcon || {};
const onExpandIconMouseDown = useEventCallback(
mergeCallbacks(onIconMouseDown, () => {
// do not dismiss on blur when clicking the icon
baseState.ignoreNextBlur.current = true;
// do not dismiss on blur when closing via clicking the icon
if (open) {
baseState.ignoreNextBlur.current = true;
}
}),
);

Expand Down

0 comments on commit f919dac

Please sign in to comment.