Skip to content

Commit

Permalink
fix: Make Select component fire onChange listener when a selection is…
Browse files Browse the repository at this point in the history
… pasted in (apache#25993)
  • Loading branch information
jfrag1 authored and sfirke committed Mar 22, 2024
1 parent e3edaa3 commit c47f316
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions superset-frontend/src/components/Select/AsyncSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,20 @@ test('fires onChange when clearing the selection in multiple mode', async () =>
expect(onChange).toHaveBeenCalledTimes(1);
});

test('fires onChange when pasting a selection', async () => {
const onChange = jest.fn();
render(<AsyncSelect {...defaultProps} onChange={onChange} />);
await open();
const input = getElementByClassName('.ant-select-selection-search-input');
const paste = createEvent.paste(input, {
clipboardData: {
getData: () => OPTIONS[0].label,
},
});
fireEvent(input, paste);
expect(onChange).toHaveBeenCalledTimes(1);
});

test('does not duplicate options when using numeric values', async () => {
render(
<AsyncSelect
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/components/Select/AsyncSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ const AsyncSelect = forwardRef(
...values,
]);
}
fireOnChange();
};

const shouldRenderChildrenOptions = useMemo(
Expand Down
14 changes: 14 additions & 0 deletions superset-frontend/src/components/Select/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,20 @@ test('fires onChange when clearing the selection in multiple mode', async () =>
expect(onChange).toHaveBeenCalledTimes(1);
});

test('fires onChange when pasting a selection', async () => {
const onChange = jest.fn();
render(<Select {...defaultProps} onChange={onChange} />);
await open();
const input = getElementByClassName('.ant-select-selection-search-input');
const paste = createEvent.paste(input, {
clipboardData: {
getData: () => OPTIONS[0].label,
},
});
fireEvent(input, paste);
expect(onChange).toHaveBeenCalledTimes(1);
});

test('does not duplicate options when using numeric values', async () => {
render(
<Select
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ const Select = forwardRef(
]);
}
}
fireOnChange();
};

return (
Expand Down

0 comments on commit c47f316

Please sign in to comment.