Skip to content

Commit

Permalink
Update placeholder when receiving new placeholder prop
Browse files Browse the repository at this point in the history
  • Loading branch information
patw0929 committed Mar 11, 2018
1 parent 7cee4a3 commit 4e9bcaf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions __tests__/TelInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,20 @@ describe('TelInput', function () { // eslint-disable-line func-names

expect(subject.state().value).toBe('+');
});

it('should change input placeholder on placeholder prop change', () => {
const subject = this.makeSubject();

subject.setProps({ placeholder: 'Phone number' });
subject.update();

expect(subject.find(TelInput).props().placeholder).toBe('Phone number');

subject.setProps({ placeholder: 'Your phone' });
subject.update();

expect(subject.find(TelInput).props().placeholder).toBe('Your phone');
});
});

describe('uncontrolled', () => {
Expand Down
6 changes: 6 additions & 0 deletions src/components/IntlTelInputApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ class IntlTelInputApp extends Component {
disabled: nextProps.disabled,
});
}

if (this.props.placeholder !== nextProps.placeholder) {
this.setState({
placeholder: nextProps.placeholder,
});
}
}

componentWillUpdate(nextProps, nextState) {
Expand Down

0 comments on commit 4e9bcaf

Please sign in to comment.