@@ -30,7 +30,7 @@ module.exports = React.createClass( {
3030 propTypes : {
3131 onClick : PropTypes . func ,
3232 onSelect : PropTypes . func . isRequired ,
33- onUpdateHighlighted : PropTypes . func
33+ onUpdateHighlighted : PropTypes . func ,
3434 } ,
3535
3636 getDefaultProps ( ) {
@@ -54,6 +54,7 @@ module.exports = React.createClass( {
5454
5555 getInitialState ( ) {
5656 return {
57+ triggerId :null ,
5758 isOpen :false ,
5859 isFocused :false ,
5960 isClosing :false ,
@@ -74,6 +75,53 @@ module.exports = React.createClass( {
7475 }
7576 } ,
7677
78+ componentDidUpdate ( prevProps , prevState ) {
79+
80+ if ( this . state . lastBlurredTimeStamp !== prevState . lastBlurredTimeStamp ) {
81+ if ( this . state . lastBlurredIndex === this . state . highlightedIndex ) {
82+ this . handleClose ( ) ;
83+ }
84+ }
85+
86+ if ( this . state . isOpen && ! prevState . isOpen ) {
87+ this . state . isClosing = false ;
88+ }
89+
90+ if ( this . state . selectedIndex !== prevState . selectedIndex ) {
91+ this . handleClose ( ) ;
92+ }
93+ else if ( this . state . isFocused && ! prevState . isFocused ) {
94+ this . setState ( { isOpen :false } ) ;
95+ }
96+ else if ( ! this . state . isFocused && prevState . isFocused ) {
97+ if ( this . refs . list ) {
98+ if ( this . isMounted ( ) && this . refs . list ) {
99+ if ( this . refs . list . getDOMNode ( ) . contains ( document . activeElement ) ) {
100+ return ;
101+ }
102+ this . setState ( { isOpen :false } )
103+ }
104+ }
105+ }
106+ else if ( this . state . isClosing && ! prevState . isClosing ) {
107+ setTimeout ( ( ) => {
108+ if ( this . state . isClosing ) {
109+ this . setState ( { isOpen :false } ) ;
110+ }
111+ } , this . props . hoverCloseDelay ) ;
112+ }
113+
114+ if ( this . props . value !== prevProps . value ) {
115+ this . handleSelect ( this . getIndexByValue ( this . props . value ) ) ;
116+ }
117+
118+ } ,
119+
120+ componentDidMount ( ) {
121+ let id = React . findDOMNode ( this . refs . button ) . getAttribute ( 'data-reactid' ) ;
122+ this . setState ( { triggerId :id } ) ;
123+ } ,
124+
77125 getIndexByValue ( value ) {
78126 let foundIndex = - 1 ;
79127 if ( this . props . options && this . props . options . length ) {
@@ -163,9 +211,6 @@ module.exports = React.createClass( {
163211 return React . findDOMNode ( this . refs . button ) ;
164212 } ,
165213
166- moveHighlight ( delta ) {
167- } ,
168-
169214 handleKeyDown ( event ) {
170215 if ( event . keyCode ) {
171216 if ( event . keyCode === KEYS . ENTER ||
@@ -199,6 +244,7 @@ module.exports = React.createClass( {
199244
200245 getPopoverContent ( ) {
201246 return < List
247+ triggerId = { this . state . triggerId }
202248 ref = 'list'
203249 options = { this . props . options }
204250 className = { this . props . listClassName }
@@ -274,8 +320,10 @@ module.exports = React.createClass( {
274320 ] ) ;
275321 return (
276322
323+
277324 < SLDSButton
278325 ref = 'button'
326+ id = { this . state . triggerId }
279327 aria-haspopup = 'true'
280328 label = { this . props . label }
281329 className = { this . props . className }
@@ -297,49 +345,7 @@ module.exports = React.createClass( {
297345 </ SLDSButton >
298346
299347 ) ;
300- } ,
301-
302- componentDidUpdate ( prevProps , prevState ) {
303-
304- if ( this . state . lastBlurredTimeStamp !== prevState . lastBlurredTimeStamp ) {
305- if ( this . state . lastBlurredIndex === this . state . highlightedIndex ) {
306- this . handleClose ( ) ;
307- }
308- }
309-
310- if ( this . state . isOpen && ! prevState . isOpen ) {
311- this . state . isClosing = false ;
312- }
313-
314- if ( this . state . selectedIndex !== prevState . selectedIndex ) {
315- this . handleClose ( ) ;
316- }
317- else if ( this . state . isFocused && ! prevState . isFocused ) {
318- this . setState ( { isOpen :false } ) ;
319- }
320- else if ( ! this . state . isFocused && prevState . isFocused ) {
321- if ( this . refs . list ) {
322- if ( this . isMounted ( ) && this . refs . list ) {
323- if ( this . refs . list . getDOMNode ( ) . contains ( document . activeElement ) ) {
324- return ;
325- }
326- this . setState ( { isOpen :false } )
327- }
328- }
329- }
330- else if ( this . state . isClosing && ! prevState . isClosing ) {
331- setTimeout ( ( ) => {
332- if ( this . state . isClosing ) {
333- this . setState ( { isOpen :false } ) ;
334- }
335- } , this . props . hoverCloseDelay ) ;
336- }
337-
338- if ( this . props . value !== prevProps . value ) {
339- this . handleSelect ( this . getIndexByValue ( this . props . value ) ) ;
340- }
341-
342- } ,
348+ }
343349
344350} ) ;
345351
0 commit comments