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..b6073948 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 // 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(); }); });