File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -138,6 +138,14 @@ const Select = React.createClass({
138138 }
139139 } ,
140140
141+ componentWillReceiveProps ( nextProps ) {
142+ if ( this . props . value !== nextProps . value && nextProps . required ) {
143+ this . setState ( {
144+ required : this . handleRequired ( nextProps . value , nextProps . multi ) ,
145+ } ) ;
146+ }
147+ } ,
148+
141149 componentWillUpdate ( nextProps , nextState ) {
142150 if ( nextState . isOpen !== this . state . isOpen ) {
143151 const handler = nextState . isOpen ? nextProps . onOpen : nextProps . onClose ;
Original file line number Diff line number Diff line change @@ -2816,6 +2816,18 @@ describe('Select', () => {
28162816 expect ( instance . state . required , 'to be true' ) ;
28172817 } ) ;
28182818
2819+ it ( 'input should not have required attribute after updating the component with a value' , ( ) => {
2820+ wrapper = createControlWithWrapper ( {
2821+ options : defaultOptions ,
2822+ value : '' ,
2823+ required : true
2824+ } ) ;
2825+
2826+ expect ( instance . state . required , 'to be true' ) ;
2827+ wrapper . setPropsForChild ( { value : 'one' } ) ;
2828+ expect ( instance . state . required , 'to be false' ) ;
2829+ } ) ;
2830+
28192831 } ) ;
28202832
28212833 describe ( 'required with multi=true' , ( ) => {
You can’t perform that action at this time.
0 commit comments