Skip to content

Commit 514002d

Browse files
author
Natalia Momotenko
committed
Merge remote-tracking branch 'origin/MAGETWO-32186' into UI
2 parents effe272 + 67e28a2 commit 514002d

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

app/code/Magento/Search/view/frontend/templates/form.mini.phtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ $helper = $this->helper('Magento\Search\Helper\Data');
3030
placeholder="<?php echo __('Search entire store here...'); ?>"
3131
class="input-text"
3232
maxlength="<?php echo $helper->getMaxQueryLength();?>"
33+
role="combobox"
34+
aria-haspopup="false"
35+
aria-autocomplete="both"
3336
autocomplete="off"/>
3437
<div id="search_autocomplete" class="search-autocomplete"></div>
3538
<?php echo $this->getChildHtml() ?>

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

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ define([
3030
minSearchLength: 2,
3131
responseFieldElements: 'ul li',
3232
selectClass: 'selected',
33-
template: '<li class="{{row_class}}" title="{{title}}">{{title}}<span class="amount">{{num_of_results}}</span></li>',
33+
template: '<li class="{{row_class}}" id="qs-option-{{index}}" role="option"><span class="qs-option-name">{{title}}</span><span aria-hidden="true" class="amount">{{num_of_results}}</span></li>',
3434
submitBtn: 'button[type="submit"]',
3535
searchLabel: '[data-role=minisearch-label]'
3636
},
@@ -55,6 +55,7 @@ define([
5555
this.searchLabel.removeClass('active');
5656
}
5757
this.autoComplete.hide();
58+
this._updateAriaHasPopup(false);
5859
}, this), 250);
5960
}, this));
6061

@@ -66,7 +67,10 @@ define([
6667
this.element.on('keydown', this._onKeyDown);
6768
this.element.on('input propertychange', this._onPropertyChange);
6869

69-
this.searchForm.on('submit', this._onSubmit);
70+
this.searchForm.on('submit', $.proxy(function() {
71+
this._onSubmit();
72+
this._updateAriaHasPopup(false);
73+
}, this));
7074
},
7175
/**
7276
* @private
@@ -84,6 +88,18 @@ define([
8488
return this.responseList.indexList ? this.responseList.indexList.last() : false;
8589
},
8690

91+
/**
92+
* @private
93+
* @param {Boolean} show Set attribute aria-haspopup to "true/false" for element.
94+
*/
95+
_updateAriaHasPopup: function(show) {
96+
if (show) {
97+
this.element.attr('aria-haspopup', 'true');
98+
} else {
99+
this.element.attr('aria-haspopup', 'false');
100+
}
101+
},
102+
87103
/**
88104
* Clears the item selected from the suggestion list and resets the suggestion list.
89105
* @private
@@ -108,9 +124,9 @@ define([
108124
if (isEmpty(value)) {
109125
e.preventDefault();
110126
}
111-
127+
112128
if (this.responseList.selected) {
113-
this.element.val(this.responseList.selected.attr('title'));
129+
this.element.val(this.responseList.selected.find('.qs-option-name').text());
114130
}
115131
},
116132

@@ -153,6 +169,8 @@ define([
153169
this._getFirstVisibleElement().addClass(this.options.selectClass);
154170
this.responseList.selected = this._getFirstVisibleElement();
155171
}
172+
this.element.val(this.responseList.selected.find('.qs-option-name').text());
173+
this.element.attr('aria-activedescendant', this.responseList.selected.attr('id'));
156174
}
157175
break;
158176
case $.ui.keyCode.UP:
@@ -165,6 +183,8 @@ define([
165183
this._getLastElement().addClass(this.options.selectClass);
166184
this.responseList.selected = this._getLastElement();
167185
}
186+
this.element.val(this.responseList.selected.find('.qs-option-name').text());
187+
this.element.attr('aria-activedescendant', this.responseList.selected.attr('id'));
168188
}
169189
break;
170190
default:
@@ -189,14 +209,15 @@ define([
189209
},
190210
source = this.options.template,
191211
template = Handlebars.compile(source),
192-
dropdown = $('<ul></ul>'),
212+
dropdown = $('<ul role="listbox"></ul>'),
193213
value = this.element.val();
194214

195215
this.submitBtn.disabled = isEmpty(value);
196216

197217
if (value.length >= parseInt(this.options.minSearchLength, 10)) {
198218
$.get(this.options.url, {q: value}, $.proxy(function (data) {
199-
$.each(data, function(index, element){
219+
$.each(data, function(index, element) {
220+
element.index = index;
200221
var html = template(element);
201222
dropdown.append(html);
202223
});
@@ -206,7 +227,14 @@ define([
206227
.find(this.options.responseFieldElements + ':visible');
207228

208229
this._resetResponseList(false);
209-
230+
this.element.removeAttr('aria-activedescendant');
231+
232+
if (this.responseList.indexList.length) {
233+
this._updateAriaHasPopup(true);
234+
} else {
235+
this._updateAriaHasPopup(false);
236+
}
237+
210238
this.responseList.indexList
211239
.on('click', function (e) {
212240
this.responseList.selected = $(e.target);
@@ -216,6 +244,7 @@ define([
216244
this.responseList.indexList.removeClass(this.options.selectClass);
217245
$(e.target).addClass(this.options.selectClass);
218246
this.responseList.selected = $(e.target);
247+
this.element.attr('aria-activedescendant', $(e.target).attr('id'));
219248
}.bind(this))
220249
.on('mouseout', function (e) {
221250
if (!this._getLastElement() && this._getLastElement().hasClass(this.options.selectClass)) {
@@ -227,6 +256,8 @@ define([
227256
} else {
228257
this._resetResponseList(true);
229258
this.autoComplete.hide();
259+
this._updateAriaHasPopup(false);
260+
this.element.removeAttr('aria-activedescendant');
230261
}
231262
}
232263
});

0 commit comments

Comments
 (0)