mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
Merge pull request #350 from koloml/autocomplete-mouse-selection
Autocomplete: Prevent autocompleted options from selecting when cursor is placed right where popup is created
This commit is contained in:
commit
11d8ca0bfd
1 changed files with 22 additions and 2 deletions
|
@ -125,18 +125,38 @@ function createItem(list: HTMLUListElement, suggestion: TermSuggestion) {
|
|||
className: 'autocomplete__item',
|
||||
});
|
||||
|
||||
let ignoreMouseOver = true;
|
||||
|
||||
item.textContent = suggestion.label;
|
||||
item.dataset.value = suggestion.value;
|
||||
|
||||
item.addEventListener('mouseover', () => {
|
||||
function onItemMouseOver() {
|
||||
// Prevent selection when mouse entered the element without actually moving.
|
||||
if (ignoreMouseOver) {
|
||||
return;
|
||||
}
|
||||
|
||||
removeSelected();
|
||||
item.classList.add('autocomplete__item--selected');
|
||||
});
|
||||
}
|
||||
|
||||
item.addEventListener('mouseover', onItemMouseOver);
|
||||
|
||||
item.addEventListener('mouseout', () => {
|
||||
removeSelected();
|
||||
});
|
||||
|
||||
item.addEventListener(
|
||||
'mousemove',
|
||||
() => {
|
||||
ignoreMouseOver = false;
|
||||
onItemMouseOver();
|
||||
},
|
||||
{
|
||||
once: true,
|
||||
},
|
||||
);
|
||||
|
||||
item.addEventListener('click', () => {
|
||||
if (!inputField || !item.dataset.value) return;
|
||||
|
||||
|
|
Loading…
Reference in a new issue