Skip to content

Commit

Permalink
Add: props support
Browse files Browse the repository at this point in the history
  • Loading branch information
lexich committed Jan 28, 2016
1 parent a3df6d9 commit ea1f431
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/components/Select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export default class Select2 extends Component {
PropTypes.array,
PropTypes.string,
]),
value: PropTypes.oneOfType([
PropTypes.number,
PropTypes.array,
PropTypes.string,
]),
data: PropTypes.array,
events: PropTypes.array,
options: PropTypes.object,
Expand Down Expand Up @@ -46,6 +51,17 @@ export default class Select2 extends Component {
this.props.events.forEach(event => {
this.el.on(event[0], this.props[event[1]]);
});
if (this.el.val() !== this.props.value) {
this.el.val(this.props.value);
}
}

componentWillReceiveProps(nextProps) {
if (this.el && nextProps.value !== this.props.value) {
if (this.el.val() !== nextProps.value) {
this.el.val(nextProps.value).trigger("change");
}
}
}

componentWillUnmount() {
Expand Down

0 comments on commit ea1f431

Please sign in to comment.