Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/hooks/useCombobox/__tests__/getInputProps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,41 @@ describe('getInputProps', () => {
expect(result.current.inputValue).toBe('lalaland')
})

test('does not update inputValue while an IME composition is in progress', () => {
const userOnChange = jest.fn()
const onInputValueChange = jest.fn()
const {result} = renderUseCombobox({onInputValueChange})

act(() => {
const {ref: inputRef, onChange} = result.current.getInputProps({
onChange: userOnChange,
})

inputRef({focus: noop})
onChange({
target: {value: 'に'},
nativeEvent: {isComposing: true},
})
})

expect(userOnChange).toHaveBeenCalledTimes(1)
expect(onInputValueChange).not.toHaveBeenCalled()
expect(result.current.inputValue).toBe('')

act(() => {
result.current.getInputProps().onChange({
target: {value: '日本'},
nativeEvent: {isComposing: false},
})
})

expect(onInputValueChange).toHaveBeenCalledTimes(1)
expect(onInputValueChange).toHaveBeenCalledWith(
expect.objectContaining({inputValue: '日本'}),
)
expect(result.current.inputValue).toBe('日本')
})

test("event handler onChange is called without downshift handler if 'preventDownshiftDefault' is passed in user event", () => {
const userOnChange = jest.fn(event => {
event.preventDownshiftDefault = true
Expand Down
14 changes: 12 additions & 2 deletions src/hooks/useCombobox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,19 @@ function useCombobox<Item>(
}
const inputHandleChange = (
event:
| React.ChangeEvent<HTMLInputElement>
| {nativeEvent: {text: string}},
React.ChangeEvent<HTMLInputElement> | {nativeEvent: {text: string}},
) => {
if (
!isReactNative &&
!isReactNativeWeb &&
(
(event as React.ChangeEvent<HTMLInputElement>)
.nativeEvent as InputEvent
)?.isComposing
) {
return
}

dispatch({
type: stateChangeTypes.InputChange,
inputValue:
Expand Down