@@ -27,30 +27,34 @@ type EventLike = {
2727class SearchPane extends React . Component {
2828 input : ReactElement ;
2929 _key : ( evt : EventLike ) => void ;
30+ constructor ( props ) {
31+ super ( props ) ;
32+ this . state = { focused : false } ;
33+ }
3034
31- componentWillMount ( ) {
32- this . _key = this . onWindowKeyDown . bind ( this ) ;
33- var win = this . props . win || window ;
34- win . addEventListener ( 'keydown' , this . _key , true ) ;
35+ componentDidMount ( ) {
36+ this . _key = this . onDocumentKeyDown . bind ( this ) ;
37+ var doc = React . findDOMNode ( this ) . ownerDocument ;
38+ doc . addEventListener ( 'keydown' , this . _key , true ) ;
3539 }
3640
3741 componentWillUnmount ( ) {
38- var win = this . props . win || window ;
39- win . removeEventListener ( 'keydown' , this . _key , true ) ;
42+ var doc = React . findDOMNode ( this ) . ownerDocument ;
43+ doc . removeEventListener ( 'keydown' , this . _key , true ) ;
4044 }
4145
42- onWindowKeyDown ( e ) {
46+ onDocumentKeyDown ( e ) {
4347 if ( e . keyCode === 191 ) { // forward slash
4448 var node = React . findDOMNode ( this . input ) ;
45- var win = this . props . win || window ;
46- if ( win . document . activeElement === node ) {
49+ var doc = React . findDOMNode ( this ) . ownerDocument ;
50+ if ( doc . activeElement === node ) {
4751 return ;
4852 }
4953 node . focus ( ) ;
5054 e . preventDefault ( ) ;
5155 }
5256 if ( e . keyCode === 27 ) { // escape
53- if ( ! this . props . searchText ) {
57+ if ( ! this . props . searchText && ! this . state . focused ) {
5458 return ;
5559 }
5660 e . stopPropagation ( ) ;
@@ -82,6 +86,8 @@ class SearchPane extends React.Component {
8286 style = { styles . input }
8387 ref = { i => this . input = i }
8488 value = { this . props . searchText }
89+ onFocus = { ( ) => this . setState ( { focused : true } ) }
90+ onBlur = { ( ) => this . setState ( { focused : false } ) }
8591 onKeyDown = { e => this . onKeyDown ( e . key ) }
8692 placeholder = "Search by Component Name"
8793 onChange = { e => this . props . onChangeSearch ( e . target . value ) }
0 commit comments