Skip to content

Commit

Permalink
[FIX] JedWatson#1651 moved option prop sync to componentWillReceivePr…
Browse files Browse the repository at this point in the history
…ops (JedWatson#1765)

* [FIX] JedWatson#1651 moved option prop sync to componentWillReceiveProps

* [ADD] test for option prop sync by componentWillReceiveProps
  • Loading branch information
cbergmiller authored and agirton committed Jun 3, 2017
1 parent 1d15068 commit 40db517
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/Async.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,12 @@ export default class Async extends Component {
}
}

componentWillUpdate (nextProps, nextState) {
const propertiesToSync = ['options'];
propertiesToSync.forEach((prop) => {
if (this.props[prop] !== nextProps[prop]) {
this.setState({
[prop]: nextProps[prop]
});
}
});
componentWillReceiveProps(nextProps) {
if (nextProps.options !== this.props.options) {
this.setState({
options: nextProps.options,
});
}
}

clearOptions() {
Expand Down
16 changes: 16 additions & 0 deletions test/Async-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,4 +447,20 @@ describe('Async', () => {
expect(input, 'to equal', document.activeElement);
});
});


describe('props sync test', () => {
it('should update options on componentWillReceiveProps', () => {
createControl({
});
asyncInstance.componentWillReceiveProps({
options: [{
label: 'bar',
value: 'foo',
}]
});
expect(asyncNode.querySelectorAll('[role=option]').length, 'to equal', 1);
expect(asyncNode.querySelector('[role=option]').textContent, 'to equal', 'bar');
});
});
});

0 comments on commit 40db517

Please sign in to comment.