Skip to content

Commit

Permalink
fix(select-field): update internal value when options change
Browse files Browse the repository at this point in the history
  • Loading branch information
dackmin committed Dec 5, 2019
1 parent 75b8218 commit 14200d6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/SelectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ class SelectField extends React.Component {
this.onPropValueChange();
}

if (prevProps.options !== this.props.options) {
this.onPropValueChange(false);
}

if (prevProps.disabled !== this.props.disabled && this.props.disabled) {
this.setState({
opened: false,
Expand Down
22 changes: 22 additions & 0 deletions tests/SelectField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,26 @@ describe('<SelectField />', () => {
component.find(DropdownItem).at(0).find('a').simulate('click');
expect(component.instance().getValue()).toBe('Five');
});

it('should update internal value when options change', () => {
const component = mount(
<SelectField
options={[]}
value={5}
parseValue={opt => opt.value}
/>
);

expect(component.instance().getValue()).not.toBeDefined();

component.setProps({
options: [
{ title: 'Four', value: 4 },
{ title: 'Five', value: 5 },
{ title: 'Six', value: 6 },
],
});

expect(component.instance().getValue()).toBe(5);
});
});

0 comments on commit 14200d6

Please sign in to comment.