Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Compositing should trigger again when ended #583

Merged
merged 1 commit into from
Dec 28, 2020
Merged
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
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