Skip to content

Commit

Permalink
Merge pull request #350 from reactioncommerce/fix-aldeed-select-clear
Browse files Browse the repository at this point in the history
fix: clear Select when value prop becomes null
  • Loading branch information
machikoyasuda authored Oct 31, 2018
2 parents 76998ac + a747deb commit e63cc4c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package/src/components/Select/v1/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ class Select extends Component {
passthroughProps[prop] = this.props[prop];
});

let optionValue;
let optionValue = null;
if (value !== undefined && value !== null) {
optionValue = reactSelectOptions.find((opt) => {
if (opt.options) return opt.options.find((o) => o.value === value);
Expand Down
8 changes: 8 additions & 0 deletions package/src/components/Select/v1/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,11 @@ test("alphabetize option snapshot", () => {
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
});

test("when value prop changes to `null`, selection is cleared", () => {
const wrapper = mount(<Select options={OPTIONS} value="c" />);
expect(wrapper.html().indexOf(">C</div>")).not.toBe(-1);

wrapper.setProps({ value: null });
expect(wrapper.html().indexOf(">Select...</div>")).not.toBe(-1);
});

0 comments on commit e63cc4c

Please sign in to comment.