Fix autocomplete tap handling
A recent change added some complexity to the DOM that makes up autocomplete suggestions. As a result, the tap handler supplied the wrong DOM element in the corresponding event fired. This change adds a loop that gets the correct DOM element for the event payload. Bug: Issue 9818 Change-Id: Ife7adcfc0a0a54031413654649fcb9cc8b27b201
This commit is contained in:
@@ -84,6 +84,7 @@ limitations under the License.
|
||||
data-value$="[[item.dataValue]]"
|
||||
tabindex="-1"
|
||||
aria-label$="[[item.name]]"
|
||||
class="autocompleteOption"
|
||||
role="option"
|
||||
on-tap="_handleTapItem">
|
||||
<span>[[item.text]]</span>
|
||||
|
@@ -59,8 +59,8 @@
|
||||
},
|
||||
|
||||
behaviors: [
|
||||
Polymer.IronFitBehavior,
|
||||
Gerrit.KeyboardShortcutBehavior,
|
||||
Polymer.IronFitBehavior,
|
||||
],
|
||||
|
||||
keyBindings: {
|
||||
@@ -140,9 +140,14 @@
|
||||
_handleTapItem(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
let selected = e.target;
|
||||
while (!selected.classList.contains('autocompleteOption')) {
|
||||
if (!selected || selected === this) { return; }
|
||||
selected = selected.parentElement;
|
||||
}
|
||||
this.fire('item-selected', {
|
||||
trigger: 'tap',
|
||||
selected: e.target,
|
||||
selected,
|
||||
});
|
||||
},
|
||||
|
||||
|
@@ -131,6 +131,19 @@ limitations under the License.
|
||||
});
|
||||
});
|
||||
|
||||
test('tapping child still selects item', () => {
|
||||
const itemSelectedStub = sandbox.stub();
|
||||
element.addEventListener('item-selected', itemSelectedStub);
|
||||
|
||||
MockInteractions.tap(element.$.suggestions.querySelectorAll('li')[0]
|
||||
.lastElementChild);
|
||||
flushAsynchronousOperations();
|
||||
assert.deepEqual(itemSelectedStub.lastCall.args[0].detail, {
|
||||
trigger: 'tap',
|
||||
selected: element.$.suggestions.querySelectorAll('li')[0],
|
||||
});
|
||||
});
|
||||
|
||||
test('updated suggestions resets cursor stops', () => {
|
||||
resetStopsSpy = sandbox.spy(element, '_resetCursorStops');
|
||||
element.suggestions = [];
|
||||
|
Reference in New Issue
Block a user