Skip to content

Commit ddbcd12

Browse files
authored
fix: Compositing should trigger again when ended (#583)
1 parent b3eb0a9 commit ddbcd12

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Selector/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface InnerSelectorProps {
4747
export interface RefSelectorProps {
4848
focus: () => void;
4949
blur: () => void;
50-
scrollTo?: ScrollTo,
50+
scrollTo?: ScrollTo;
5151
}
5252

5353
export interface SelectorProps {
@@ -172,8 +172,9 @@ const Selector: React.RefForwardingComponent<RefSelectorProps, SelectorProps> =
172172
compositionStatusRef.current = true;
173173
};
174174

175-
const onInputCompositionEnd = () => {
175+
const onInputCompositionEnd: React.CompositionEventHandler<HTMLInputElement> = e => {
176176
compositionStatusRef.current = false;
177+
triggerOnSearch((e.target as HTMLInputElement).value);
177178
};
178179

179180
const onInputChange: React.ChangeEventHandler<HTMLInputElement> = event => {

tests/Tags.test.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('Select.Tags', () => {
8686
expectOpen(wrapper, false);
8787
});
8888

89-
it("shounld't separate words when compositing", () => {
89+
it('should not separate words when compositing but trigger after composition end', () => {
9090
const handleChange = jest.fn();
9191
const handleSelect = jest.fn();
9292
const wrapper = mount(
@@ -96,13 +96,16 @@ describe('Select.Tags', () => {
9696
</Select>,
9797
);
9898

99-
wrapper.find('input').simulate('compositionstart');
99+
// composition start
100+
wrapper.find('input').simulate('compositionStart');
100101
wrapper.find('input').simulate('change', { target: { value: '2,3,4' } });
101102
expect(handleChange).not.toHaveBeenCalled();
102103
handleChange.mockReset();
103-
wrapper.find('input').simulate('compositionend');
104-
wrapper.find('input').simulate('change', { target: { value: '2,3,4' } });
104+
105+
// composition end
106+
wrapper.find('input').simulate('compositionEnd');
105107
expect(handleChange).toHaveBeenCalledWith(['2', '3', '4'], expect.anything());
108+
106109
expect(handleSelect).toHaveBeenCalledTimes(3);
107110
expect(handleSelect).toHaveBeenLastCalledWith('4', expect.anything());
108111
expect(findSelection(wrapper).text()).toEqual('2');

0 commit comments

Comments
 (0)