Skip to content

Commit

Permalink
fix: Compositing should trigger again when ended (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ authored Dec 28, 2020
1 parent b3eb0a9 commit ddbcd12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Selector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface InnerSelectorProps {
export interface RefSelectorProps {
focus: () => void;
blur: () => void;
scrollTo?: ScrollTo,
scrollTo?: ScrollTo;
}

export interface SelectorProps {
Expand Down Expand Up @@ -172,8 +172,9 @@ const Selector: React.RefForwardingComponent<RefSelectorProps, SelectorProps> =
compositionStatusRef.current = true;
};

const onInputCompositionEnd = () => {
const onInputCompositionEnd: React.CompositionEventHandler<HTMLInputElement> = e => {
compositionStatusRef.current = false;
triggerOnSearch((e.target as HTMLInputElement).value);
};

const onInputChange: React.ChangeEventHandler<HTMLInputElement> = event => {
Expand Down
11 changes: 7 additions & 4 deletions tests/Tags.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('Select.Tags', () => {
expectOpen(wrapper, false);
});

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

wrapper.find('input').simulate('compositionstart');
// composition start
wrapper.find('input').simulate('compositionStart');
wrapper.find('input').simulate('change', { target: { value: '2,3,4' } });
expect(handleChange).not.toHaveBeenCalled();
handleChange.mockReset();
wrapper.find('input').simulate('compositionend');
wrapper.find('input').simulate('change', { target: { value: '2,3,4' } });

// composition end
wrapper.find('input').simulate('compositionEnd');
expect(handleChange).toHaveBeenCalledWith(['2', '3', '4'], expect.anything());

expect(handleSelect).toHaveBeenCalledTimes(3);
expect(handleSelect).toHaveBeenLastCalledWith('4', expect.anything());
expect(findSelection(wrapper).text()).toEqual('2');
Expand Down

1 comment on commit ddbcd12

@vercel
Copy link

@vercel vercel bot commented on ddbcd12 Dec 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.