diff --git a/src/hooks/useCombobox/index.js b/src/hooks/useCombobox/index.js index 1bc68c74..45a68716 100644 --- a/src/hooks/useCombobox/index.js +++ b/src/hooks/useCombobox/index.js @@ -334,7 +334,7 @@ function useCombobox(userProps = {}) { index, }) } - const itemHandleMouseDown = e => e.preventDefault() + const itemHandleMouseDown = e => e.preventDefault() // keep focus on the input after item click select. return { [refKey]: handleRefs(ref, itemNode => { diff --git a/src/hooks/useSelect/__tests__/getToggleButtonProps.test.js b/src/hooks/useSelect/__tests__/getToggleButtonProps.test.js index db6cd3ed..aa44f73d 100644 --- a/src/hooks/useSelect/__tests__/getToggleButtonProps.test.js +++ b/src/hooks/useSelect/__tests__/getToggleButtonProps.test.js @@ -1709,6 +1709,24 @@ describe('getToggleButtonProps', () => { }) describe('blur', () => { + test('with the menu closed does nothing', async () => { + const initialHighlightedIndex = 2 + renderSelect({initialHighlightedIndex}, ui => { + return ( + <> + {ui} +
Second element
+ + ) + }) + + await tab() // focus the button + screen.getByText(/Second element/).focus() + + expect(getItems()).toHaveLength(0) + expect(getToggleButton()).not.toHaveTextContent() + }) + test('by focusing another element should behave as a normal blur', async () => { const initialHighlightedIndex = 2 renderSelect({initialIsOpen: true, initialHighlightedIndex}, ui => { diff --git a/src/hooks/useSelect/index.js b/src/hooks/useSelect/index.js index fcc8d82b..16c4f78f 100644 --- a/src/hooks/useSelect/index.js +++ b/src/hooks/useSelect/index.js @@ -490,7 +490,7 @@ function useSelect(userProps = {}) { index, }) } - const itemHandleMouseDown = e => e.preventDefault() + const itemHandleMouseDown = e => e.preventDefault() // keep focus on the toggle after item click select. const itemProps = { [refKey]: handleRefs(ref, itemNode => {