Skip to content

Commit 28c0b5b

Browse files
committed
fix: commit compositionend-only combobox input
1 parent ee3fe77 commit 28c0b5b

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/Select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
653653
}
654654

655655
if (info.source !== 'blur') {
656-
if (mode === 'combobox' && !info.isCompositionEnd) {
656+
if (mode === 'combobox') {
657657
triggerChange(searchText);
658658
}
659659

tests/Select.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,24 @@ describe('Select.Basic', () => {
798798
expect(handleChange).toHaveBeenCalledTimes(1);
799799
});
800800

801+
it('commits combobox composition text when compositionend is the first value event', () => {
802+
const handleSearch = jest.fn();
803+
const handleChange = jest.fn();
804+
const { container } = render(
805+
<Select mode="combobox" onSearch={handleSearch} onChange={handleChange} />,
806+
);
807+
const input = container.querySelector('input');
808+
809+
fireEvent.compositionStart(input);
810+
input.value = '中文';
811+
fireEvent.compositionEnd(input);
812+
813+
expect(handleSearch).toHaveBeenCalledTimes(1);
814+
expect(handleSearch).toHaveBeenCalledWith('中文', { isComposing: false });
815+
expect(handleChange).toHaveBeenCalledTimes(1);
816+
expect(handleChange).toHaveBeenCalledWith('中文', {});
817+
});
818+
801819
it('not fires search event when user select', () => {
802820
const handleSearch = jest.fn();
803821
const { container } = render(

0 commit comments

Comments
 (0)