From 081f47e779fbc113a0baf446a6c724d5ca0c56cd Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 26 Oct 2017 09:26:19 -0400 Subject: [PATCH] Components: Detect autocomplete blur by click outside menu --- components/autocomplete/index.js | 10 +++++----- components/autocomplete/test/index.js | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/components/autocomplete/index.js b/components/autocomplete/index.js index 9247198130ce78..04b5c693b50885 100644 --- a/components/autocomplete/index.js +++ b/components/autocomplete/index.js @@ -31,7 +31,7 @@ class Autocomplete extends Component { constructor() { super( ...arguments ); - this.bindNode = this.bindNode.bind( this ); + this.bindMenuNode = this.bindMenuNode.bind( this ); this.select = this.select.bind( this ); this.reset = this.reset.bind( this ); this.onBlur = this.onBlur.bind( this ); @@ -41,8 +41,8 @@ class Autocomplete extends Component { this.state = this.constructor.getInitialState(); } - bindNode( node ) { - this.node = node; + bindMenuNode( node ) { + this.menuNode = node; } select( option ) { @@ -62,7 +62,7 @@ class Autocomplete extends Component { onBlur( event ) { // Check if related target is not within, in the case that the user is // selecting an option by button click - if ( ! this.node.contains( event.relatedTarget ) ) { + if ( ! this.menuNode.contains( event.relatedTarget ) ) { this.reset(); } } @@ -189,7 +189,6 @@ class Autocomplete extends Component { // the event will not have `relatedTarget` assigned. return (
@@ -206,6 +205,7 @@ class Autocomplete extends Component {