Skip to content

Commit 316c516

Browse files
Merge forwardport of #11246 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/11246.patch (created by @crissanclick) based on commit(s): 1. 79f9c8a 2. 154dd01 3. c17b3eb Fixed GitHub Issues in 2.3-develop branch: - #11231: Can't close mobile search bar once typed (reported by @BenSpace48)
2 parents 44d5334 + 9701bb7 commit 316c516

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed

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

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -286,46 +286,50 @@ define([
286286
$.getJSON(this.options.url, {
287287
q: value
288288
}, $.proxy(function (data) {
289-
$.each(data, function (index, element) {
290-
var html;
291-
292-
element.index = index;
293-
html = template({
294-
data: element
289+
if (data.length) {
290+
$.each(data, function (index, element) {
291+
var html;
292+
293+
element.index = index;
294+
html = template({
295+
data: element
296+
});
297+
dropdown.append(html);
295298
});
296-
dropdown.append(html);
297-
});
298-
this.responseList.indexList = this.autoComplete.html(dropdown)
299-
.css(clonePosition)
300-
.show()
301-
.find(this.options.responseFieldElements + ':visible');
302-
303-
this._resetResponseList(false);
304-
this.element.removeAttr('aria-activedescendant');
305-
306-
if (this.responseList.indexList.length) {
307-
this._updateAriaHasPopup(true);
308-
} else {
309-
this._updateAriaHasPopup(false);
310-
}
311299

312-
this.responseList.indexList
313-
.on('click', function (e) {
314-
this.responseList.selected = $(e.currentTarget);
315-
this.searchForm.trigger('submit');
316-
}.bind(this))
317-
.on('mouseenter mouseleave', function (e) {
318-
this.responseList.indexList.removeClass(this.options.selectClass);
319-
$(e.target).addClass(this.options.selectClass);
320-
this.responseList.selected = $(e.target);
321-
this.element.attr('aria-activedescendant', $(e.target).attr('id'));
322-
}.bind(this))
323-
.on('mouseout', function (e) {
324-
if (!this._getLastElement() && this._getLastElement().hasClass(this.options.selectClass)) {
325-
$(e.target).removeClass(this.options.selectClass);
326-
this._resetResponseList(false);
327-
}
328-
}.bind(this));
300+
this.responseList.indexList = this.autoComplete.html(dropdown)
301+
.css(clonePosition)
302+
.show()
303+
.find(this.options.responseFieldElements + ':visible');
304+
305+
this._resetResponseList(false);
306+
this.element.removeAttr('aria-activedescendant');
307+
308+
if (this.responseList.indexList.length) {
309+
this._updateAriaHasPopup(true);
310+
} else {
311+
this._updateAriaHasPopup(false);
312+
}
313+
314+
this.responseList.indexList
315+
.on('click', function (e) {
316+
this.responseList.selected = $(e.currentTarget);
317+
this.searchForm.trigger('submit');
318+
}.bind(this))
319+
.on('mouseenter mouseleave', function (e) {
320+
this.responseList.indexList.removeClass(this.options.selectClass);
321+
$(e.target).addClass(this.options.selectClass);
322+
this.responseList.selected = $(e.target);
323+
this.element.attr('aria-activedescendant', $(e.target).attr('id'));
324+
}.bind(this))
325+
.on('mouseout', function (e) {
326+
if (!this._getLastElement() &&
327+
this._getLastElement().hasClass(this.options.selectClass)) {
328+
$(e.target).removeClass(this.options.selectClass);
329+
this._resetResponseList(false);
330+
}
331+
}.bind(this));
332+
}
329333
}, this));
330334
} else {
331335
this._resetResponseList(true);

0 commit comments

Comments
 (0)