Skip to content

Commit

Permalink
fix useCombobox
Browse files Browse the repository at this point in the history
  • Loading branch information
silviuaavram committed Apr 11, 2020
1 parent d72a479 commit bc6af26
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/hooks/useCombobox/__tests__/getInputProps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,29 @@ describe('getInputProps', () => {
)
})

test('enter while IME composing will not select highlighted item', () => {
const initialHighlightedIndex = 2
const {keyDownOnInput, input, getItems} = renderCombobox({
initialHighlightedIndex,
initialIsOpen: true,
})

keyDownOnInput('Enter', {keyCode: 229})

expect(input.value).toEqual('')
expect(getItems()).toHaveLength(items.length)
expect(input).toHaveAttribute(
'aria-activedescendant',
defaultIds.getItemId(initialHighlightedIndex),
)

keyDownOnInput('Enter')

expect(input.value).toEqual(items[2])
expect(getItems()).toHaveLength(0)
expect(input).not.toHaveAttribute('aria-activedescendant')
})

test('tab it closes the menu and selects highlighted item', () => {
const initialHighlightedIndex = 2
const {input, getItems} = renderCombobox(
Expand Down
5 changes: 5 additions & 0 deletions src/hooks/useCombobox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ function useCombobox(userProps = {}) {
})
},
Enter(event) {
// if IME composing, wait for next Enter keydown event.
if (event.which === 229) {
return
}

event.preventDefault()
dispatch({
type: stateChangeTypes.InputKeyDownEnter,
Expand Down

0 comments on commit bc6af26

Please sign in to comment.