@@ -71,14 +71,18 @@ define([
71
71
} . bind ( this )
72
72
} ) ;
73
73
74
+ this . searchLabel . on ( 'click' , function ( e ) {
75
+ // allow input to lose its' focus when clicking on label
76
+ if ( this . isExpandable && this . isActive ( ) ) {
77
+ e . preventDefault ( ) ;
78
+ }
79
+ } . bind ( this ) ) ;
80
+
74
81
this . element . on ( 'blur' , $ . proxy ( function ( ) {
75
82
76
83
setTimeout ( $ . proxy ( function ( ) {
77
84
if ( this . autoComplete . is ( ':hidden' ) ) {
78
- this . searchLabel . removeClass ( 'active' ) ;
79
- if ( this . isExpandable === true ) {
80
- this . element . attr ( 'aria-expanded' , 'false' ) ;
81
- }
85
+ this . setActiveState ( false ) ;
82
86
}
83
87
this . autoComplete . hide ( ) ;
84
88
this . _updateAriaHasPopup ( false ) ;
@@ -87,12 +91,7 @@ define([
87
91
88
92
this . element . trigger ( 'blur' ) ;
89
93
90
- this . element . on ( 'focus' , $ . proxy ( function ( ) {
91
- this . searchLabel . addClass ( 'active' ) ;
92
- if ( this . isExpandable === true ) {
93
- this . element . attr ( 'aria-expanded' , 'true' ) ;
94
- }
95
- } , this ) ) ;
94
+ this . element . on ( 'focus' , this . setActiveState . bind ( this , true ) ) ;
96
95
this . element . on ( 'keydown' , this . _onKeyDown ) ;
97
96
this . element . on ( 'input propertychange' , this . _onPropertyChange ) ;
98
97
@@ -101,6 +100,29 @@ define([
101
100
this . _updateAriaHasPopup ( false ) ;
102
101
} , this ) ) ;
103
102
} ,
103
+
104
+ /**
105
+ * Checks if search field is active.
106
+ *
107
+ * @returns {Boolean }
108
+ */
109
+ isActive : function ( ) {
110
+ return this . searchLabel . hasClass ( 'active' ) ;
111
+ } ,
112
+
113
+ /**
114
+ * Sets state of the search field to provided value.
115
+ *
116
+ * @param {Boolean } isActive
117
+ */
118
+ setActiveState : function ( isActive ) {
119
+ this . searchLabel . toggleClass ( 'active' , isActive ) ;
120
+
121
+ if ( this . isExpandable ) {
122
+ this . element . attr ( 'aria-expanded' , isActive ) ;
123
+ }
124
+ } ,
125
+
104
126
/**
105
127
* @private
106
128
* @return {Element } The first element in the suggestion list.
0 commit comments