Skip to content

Commit 32f3572

Browse files
author
Volodymyr Zaets
committed
MAGETWO-44647: Broken keyboard navigation in ui-select
1 parent ffa02d8 commit 32f3572

File tree

2 files changed

+48
-17
lines changed

2 files changed

+48
-17
lines changed

app/code/Magento/Ui/view/base/web/js/form/element/ui-select.js

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ define([
77
'underscore',
88
'./abstract',
99
'Magento_Ui/js/lib/key-codes',
10-
'mage/translate'
11-
], function (_, Abstract, keyCodes, $t) {
10+
'mage/translate',
11+
'jquery'
12+
], function (_, Abstract, keyCodes, $t, $) {
1213
'use strict';
1314

1415
/**
@@ -46,6 +47,7 @@ define([
4647
filterInputValue: '',
4748
filterOptionsFocus: false,
4849
multiselectFocus: false,
50+
mouseSenvity: null,
4951
selectedPlaceholders: {
5052
defaultPlaceholder: $t('Select...'),
5153
lotPlaceholders: $t('Selected')
@@ -239,9 +241,7 @@ define([
239241
},
240242

241243
/**
242-
* get filtered value
243-
*
244-
* @returns {Array} filtered array
244+
* Get filtered value*
245245
*/
246246
getValue: function () {
247247
var options = this.options(),
@@ -255,7 +255,7 @@ define([
255255
},
256256

257257
/**
258-
* get selected element labels
258+
* Get selected element labels
259259
*
260260
* @returns {Array} array labels
261261
*/
@@ -301,16 +301,45 @@ define([
301301
*
302302
* @param {Object} data - object with data about this element
303303
* @param {Number} index - element index
304+
* @param {Object} event - mousemove event
305+
*/
306+
307+
onMousemove: function (data, index, event) {
308+
var target = $(event.target),
309+
id;
310+
311+
if (this.isCursorPositionChange(event)) {
312+
return false;
313+
}
314+
315+
target.is('li') ? id = target.index() : id = target.parent('li').index();
316+
id !== this.hoverElIndex() ? this.hoverElIndex(id) : false;
317+
318+
this.setCursorPosition(event);
319+
},
320+
321+
/**
322+
* Set X and Y cursor position
323+
*
324+
* @param {Object} event - mousemove event
304325
*/
305-
onHoveredIn: function (data, index) {
306-
this.hoverElIndex(index);
326+
setCursorPosition: function (event) {
327+
this.cursorPosition = {
328+
x: event.pageX,
329+
y: event.pageY
330+
};
307331
},
308332

309333
/**
310-
* Remove hover to some list element and write element ID from variable
334+
* Check previous and current cursor position
335+
*
336+
* @param {Object} event - mousemove event
337+
* @returns {Boolean}
311338
*/
312-
onHoveredOut: function () {
313-
this.hoverElIndex(null);
339+
isCursorPositionChange: function (event) {
340+
return this.cursorPosition &&
341+
this.cursorPosition.x === event.pageX &&
342+
this.cursorPosition.y === event.pageY;
314343
},
315344

316345
/**
@@ -360,6 +389,7 @@ define([
360389
if (this.hoverElIndex() !== this.options().length - 1) {
361390
this.hoverElIndex(this.hoverElIndex() + 1);
362391
} else {
392+
this.mouseSenvity = 0;
363393
this.hoverElIndex(0);
364394
}
365395
} else {
@@ -394,7 +424,7 @@ define([
394424
var keyName = keyCodes[event.keyCode];
395425

396426
if (this.isTabKey(event)) {
397-
if (!this.filterOptionsFocus() && this.listVisible() && this.filterOptions ) {
427+
if (!this.filterOptionsFocus() && this.listVisible() && this.filterOptions) {
398428
this.cacheUiSelect.blur();
399429
this.filterOptionsFocus(true);
400430
this.cleanHoveredElement();

app/code/Magento/Ui/view/base/web/templates/grid/filters/elements/ui-select.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@
8888
</label>
8989
</div>
9090
<!-- /ko -->
91-
<ul class="admin__action-multiselect-menu-inner">
91+
<ul class="admin__action-multiselect-menu-inner"
92+
data-bind="
93+
event: {
94+
mousemove: function(){onMousemove($data, $index(), event)}
95+
}
96+
">
9297
<!-- ko foreach: { data: options, as: 'option'} -->
9398
<li
9499
class="action-menu-item"
@@ -97,10 +102,6 @@
97102
_selected: $parent.isSelected(option.value),
98103
_hover: $parent.isHovered($index(), $element)
99104
},
100-
event: {
101-
mouseenter: function(){$parent.onHoveredIn($data, $index())},
102-
mouseleave: function(){$parent.onHoveredOut($data, $index())},
103-
},
104105
click: $parent.toggleOptionSelected.bind($parent, $data, $index())">
105106
<input
106107
class="admin__control-checkbox"

0 commit comments

Comments
 (0)