Files
gerrit/polygerrit-ui/app/elements/shared/gr-autocomplete-dropdown/gr-autocomplete-dropdown.html
Kasper Nilsson 027791e16d 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
2018-10-08 11:03:22 -07:00

106 lines
3.1 KiB
HTML

<!--
@license
Copyright (C) 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
<link rel="import" href="../../../bower_components/iron-dropdown/iron-dropdown.html">
<link rel="import" href="../../shared/gr-cursor-manager/gr-cursor-manager.html">
<script src="../../../scripts/rootElement.js"></script>
<link rel="import" href="../../../styles/shared-styles.html">
<dom-module id="gr-autocomplete-dropdown">
<template>
<style include="shared-styles">
:host {
z-index: 100;
}
:host([is-hidden]) {
display: none;
}
ul {
list-style: none;
}
li {
border-bottom: 1px solid var(--border-color);
cursor: pointer;
display: flex;
justify-content: space-between;
padding: .5em .75em;
}
li:last-of-type {
border: none;
}
li:focus {
outline: none;
}
li:hover {
background-color: var(--hover-background-color);
}
li.selected {
background-color: var(--selection-background-color);
}
.dropdown-content {
background: var(--dropdown-background-color);
box-shadow: rgba(0, 0, 0, 0.3) 0 1px 3px;
max-height: 50vh;
overflow: auto;
}
@media only screen and (max-height: 35em) {
.dropdown-content {
max-height: 80vh;
}
}
.label {
color: var(--deemphasized-text-color);
padding-left: 1em;
}
.hide {
display: none;
}
</style>
<div
class="dropdown-content"
slot="dropdown-content"
id="suggestions"
role="listbox">
<ul>
<template is="dom-repeat" items="[[suggestions]]">
<li data-index$="[[index]]"
data-value$="[[item.dataValue]]"
tabindex="-1"
aria-label$="[[item.name]]"
class="autocompleteOption"
role="option"
on-tap="_handleTapItem">
<span>[[item.text]]</span>
<span class$="label [[_computeLabelClass(item)]]">[[item.label]]</span>
</li>
</template>
</ul>
</div>
<gr-cursor-manager
id="cursor"
index="{{index}}"
cursor-target-class="selected"
scroll-behavior="never"
focus-on-move
stops="[[_suggestionEls]]"></gr-cursor-manager>
</template>
<script src="gr-autocomplete-dropdown.js"></script>
</dom-module>