Skip to content

Commit 81c0b41

Browse files
Merge branch 'MAGETWO-53263' of github.com:magento-vanilla/magento2ce into PR
2 parents b876a04 + 32a8550 commit 81c0b41

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

app/code/Magento/Search/view/frontend/web/form-mini.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,18 @@ define([
7171
}.bind(this)
7272
});
7373

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+
7481
this.element.on('blur', $.proxy(function () {
7582

7683
setTimeout($.proxy(function () {
7784
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);
8286
}
8387
this.autoComplete.hide();
8488
this._updateAriaHasPopup(false);
@@ -87,12 +91,7 @@ define([
8791

8892
this.element.trigger('blur');
8993

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));
9695
this.element.on('keydown', this._onKeyDown);
9796
this.element.on('input propertychange', this._onPropertyChange);
9897

@@ -101,6 +100,29 @@ define([
101100
this._updateAriaHasPopup(false);
102101
}, this));
103102
},
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+
104126
/**
105127
* @private
106128
* @return {Element} The first element in the suggestion list.

0 commit comments

Comments
 (0)