This is an automated email from the ASF dual-hosted git repository.

arivero pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 5fccf67cdc fix: Make Select component fire onChange listener when a 
selection is pasted in (#25993)
5fccf67cdc is described below

commit 5fccf67cdc4a84edb067a3cde48efacc76dbe33a
Author: Jack Fragassi <[email protected]>
AuthorDate: Thu Nov 16 12:06:05 2023 -0800

    fix: Make Select component fire onChange listener when a selection is 
pasted in (#25993)
---
 .../src/components/Select/AsyncSelect.test.tsx             | 14 ++++++++++++++
 superset-frontend/src/components/Select/AsyncSelect.tsx    |  1 +
 superset-frontend/src/components/Select/Select.test.tsx    | 14 ++++++++++++++
 superset-frontend/src/components/Select/Select.tsx         |  1 +
 4 files changed, 30 insertions(+)

diff --git a/superset-frontend/src/components/Select/AsyncSelect.test.tsx 
b/superset-frontend/src/components/Select/AsyncSelect.test.tsx
index c1442a6b70..0bb24b474a 100644
--- a/superset-frontend/src/components/Select/AsyncSelect.test.tsx
+++ b/superset-frontend/src/components/Select/AsyncSelect.test.tsx
@@ -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
diff --git a/superset-frontend/src/components/Select/AsyncSelect.tsx 
b/superset-frontend/src/components/Select/AsyncSelect.tsx
index 20de7bb591..d102af7483 100644
--- a/superset-frontend/src/components/Select/AsyncSelect.tsx
+++ b/superset-frontend/src/components/Select/AsyncSelect.tsx
@@ -554,6 +554,7 @@ const AsyncSelect = forwardRef(
           ...values,
         ]);
       }
+      fireOnChange();
     };
 
     const shouldRenderChildrenOptions = useMemo(
diff --git a/superset-frontend/src/components/Select/Select.test.tsx 
b/superset-frontend/src/components/Select/Select.test.tsx
index a6b8307582..2910353295 100644
--- a/superset-frontend/src/components/Select/Select.test.tsx
+++ b/superset-frontend/src/components/Select/Select.test.tsx
@@ -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
diff --git a/superset-frontend/src/components/Select/Select.tsx 
b/superset-frontend/src/components/Select/Select.tsx
index 6ccc1e1715..1e3bc73758 100644
--- a/superset-frontend/src/components/Select/Select.tsx
+++ b/superset-frontend/src/components/Select/Select.tsx
@@ -571,6 +571,7 @@ const Select = forwardRef(
           ]);
         }
       }
+      fireOnChange();
     };
 
     return (

Reply via email to