This is an automated email from the ASF dual-hosted git repository.
michaelsmolina 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 8061d5cce9 fix: Fires onChange when clearing all values of single
select (#25853)
8061d5cce9 is described below
commit 8061d5cce982b0b828f5de69647a1f5b75f41a46
Author: Michael S. Molina <[email protected]>
AuthorDate: Fri Nov 3 10:35:43 2023 -0300
fix: Fires onChange when clearing all values of single select (#25853)
---
.../src/components/Select/AsyncSelect.test.tsx | 28 ++++++++++++++++++++++
.../src/components/Select/Select.test.tsx | 28 ++++++++++++++++++++++
superset-frontend/src/components/Select/Select.tsx | 2 +-
3 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/superset-frontend/src/components/Select/AsyncSelect.test.tsx
b/superset-frontend/src/components/Select/AsyncSelect.test.tsx
index e49f00be53..c1442a6b70 100644
--- a/superset-frontend/src/components/Select/AsyncSelect.test.tsx
+++ b/superset-frontend/src/components/Select/AsyncSelect.test.tsx
@@ -840,6 +840,34 @@ test('does not fire onChange when searching but no
selection', async () => {
expect(onChange).toHaveBeenCalledTimes(1);
});
+test('fires onChange when clearing the selection in single mode', async () => {
+ const onChange = jest.fn();
+ render(
+ <AsyncSelect
+ {...defaultProps}
+ onChange={onChange}
+ mode="single"
+ value={OPTIONS[0]}
+ />,
+ );
+ clearAll();
+ expect(onChange).toHaveBeenCalledTimes(1);
+});
+
+test('fires onChange when clearing the selection in multiple mode', async ()
=> {
+ const onChange = jest.fn();
+ render(
+ <AsyncSelect
+ {...defaultProps}
+ onChange={onChange}
+ mode="multiple"
+ value={OPTIONS[0]}
+ />,
+ );
+ clearAll();
+ expect(onChange).toHaveBeenCalledTimes(1);
+});
+
test('does not duplicate options when using numeric values', async () => {
render(
<AsyncSelect
diff --git a/superset-frontend/src/components/Select/Select.test.tsx
b/superset-frontend/src/components/Select/Select.test.tsx
index 52e566df17..a6b8307582 100644
--- a/superset-frontend/src/components/Select/Select.test.tsx
+++ b/superset-frontend/src/components/Select/Select.test.tsx
@@ -957,6 +957,34 @@ test('does not fire onChange when searching but no
selection', async () => {
expect(onChange).toHaveBeenCalledTimes(1);
});
+test('fires onChange when clearing the selection in single mode', async () => {
+ const onChange = jest.fn();
+ render(
+ <Select
+ {...defaultProps}
+ onChange={onChange}
+ mode="single"
+ value={OPTIONS[0]}
+ />,
+ );
+ clearAll();
+ expect(onChange).toHaveBeenCalledTimes(1);
+});
+
+test('fires onChange when clearing the selection in multiple mode', async ()
=> {
+ const onChange = jest.fn();
+ render(
+ <Select
+ {...defaultProps}
+ onChange={onChange}
+ mode="multiple"
+ value={OPTIONS[0]}
+ />,
+ );
+ clearAll();
+ 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 907850a456..6ccc1e1715 100644
--- a/superset-frontend/src/components/Select/Select.tsx
+++ b/superset-frontend/src/components/Select/Select.tsx
@@ -281,8 +281,8 @@ const Select = forwardRef(
: option.value,
),
);
- fireOnChange();
}
+ fireOnChange();
};
const handleOnDeselect: SelectProps['onDeselect'] = (value, option) => {