From 26f0f4ed90a960710a643391e88700c424d9dc0e Mon Sep 17 00:00:00 2001 From: chirag Date: Wed, 17 Mar 2021 11:32:24 +0530 Subject: [PATCH 1/2] feat(HybridSelect): add eventFrom argument onChange function --- catalog/pages/inputs/index.md | 2 +- src/components/Input/HybridDropDown/HybridSelect.js | 6 +++--- src/components/Input/__tests__/HybridDropDown.spec.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/catalog/pages/inputs/index.md b/catalog/pages/inputs/index.md index 9ab99b59..482a7d8e 100644 --- a/catalog/pages/inputs/index.md +++ b/catalog/pages/inputs/index.md @@ -1012,7 +1012,7 @@ rows: - Prop: onChange Type: function Default: null - Notes: Invoked with an array of updatedSelection when an option is selected by the user + Notes: Invoked with an array of updatedSelection and eventFrom ["select" or "dropdown"] when an option is selected by the user - Prop: placeholder Type: string Default: "" diff --git a/src/components/Input/HybridDropDown/HybridSelect.js b/src/components/Input/HybridDropDown/HybridSelect.js index 8b4cdd46..90e65c74 100644 --- a/src/components/Input/HybridDropDown/HybridSelect.js +++ b/src/components/Input/HybridDropDown/HybridSelect.js @@ -6,10 +6,10 @@ import Select from "../Select/Select"; class HybridSelect extends Component { // onChange function called when value is changed - onChange = value => { + onChange = (value, eventFrom) => { const { onChange } = this.props; if (onChange) { - onChange(value); + onChange(value, eventFrom || "dropdown"); } }; @@ -35,7 +35,7 @@ class HybridSelect extends Component { selectRef = React.createRef(); // update function called when value of native select is changed - updateValue = e => this.onChange([e.target.value]); // passing value in array to match dropdown's format + updateValue = e => this.onChange([e.target.value], "select"); // passing value in array to match dropdown's format and eventFrom parameter // To add optionFor prop to the children renderChildren = (extraProps, children) => { diff --git a/src/components/Input/__tests__/HybridDropDown.spec.js b/src/components/Input/__tests__/HybridDropDown.spec.js index 9461a018..68a40a70 100644 --- a/src/components/Input/__tests__/HybridDropDown.spec.js +++ b/src/components/Input/__tests__/HybridDropDown.spec.js @@ -80,7 +80,7 @@ describe("HybridDropDown", () => { fireEvent.click(getByTestId("test-hybridoption")); expect(onChange).toHaveBeenCalledTimes(1); - expect(onChange).toHaveBeenCalledWith(["2"]); + expect(onChange).toHaveBeenCalledWith(["2"], "dropdown"); }); it("should call onChange when updateValue is called", () => { @@ -88,7 +88,7 @@ describe("HybridDropDown", () => { const spyOnChange = jest.spyOn(instance, "onChange"); instance.updateValue({ target: { value: "1" } }); expect(spyOnChange).toHaveBeenCalledTimes(1); - expect(spyOnChange).toHaveBeenCalledWith(["1"]); + expect(spyOnChange).toHaveBeenCalledWith(["1"], "select"); spyOnChange.mockRestore(); }); }); From 800db16abbc3ff31322549d72af8309a3481026e Mon Sep 17 00:00:00 2001 From: chirag Date: Wed, 17 Mar 2021 11:44:54 +0530 Subject: [PATCH 2/2] feat(HybridSelect): fix comment --- src/components/Input/HybridDropDown/HybridSelect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Input/HybridDropDown/HybridSelect.js b/src/components/Input/HybridDropDown/HybridSelect.js index 90e65c74..b6073948 100644 --- a/src/components/Input/HybridDropDown/HybridSelect.js +++ b/src/components/Input/HybridDropDown/HybridSelect.js @@ -35,7 +35,7 @@ class HybridSelect extends Component { selectRef = React.createRef(); // update function called when value of native select is changed - updateValue = e => this.onChange([e.target.value], "select"); // passing value in array to match dropdown's format and eventFrom parameter + updateValue = e => this.onChange([e.target.value], "select"); // passing value in array to match dropdown's format // To add optionFor prop to the children renderChildren = (extraProps, children) => {