Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(HybridSelect): add eventFrom argument onChange function #713

Merged
merged 2 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion catalog/pages/inputs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down
6 changes: 3 additions & 3 deletions src/components/Input/HybridDropDown/HybridSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
};

Expand All @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Input/__tests__/HybridDropDown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ 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", () => {
const instance = renderer.create(testComponentHTML()).getInstance();
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();
});
});