Moving mouseover handler into function for calling it from mousemove

This commit is contained in:
KoloMl 2024-08-29 21:07:42 +04:00
parent c8bd0c9c33
commit 53d345ddff

View file

@ -130,7 +130,7 @@ function createItem(list: HTMLUListElement, suggestion: TermSuggestion) {
item.textContent = suggestion.label; item.textContent = suggestion.label;
item.dataset.value = suggestion.value; item.dataset.value = suggestion.value;
item.addEventListener('mouseover', () => { function onItemMouseOver() {
// Prevent selection when mouse entered the element without actually moving. // Prevent selection when mouse entered the element without actually moving.
if (ignoreMouseOver) { if (ignoreMouseOver) {
return; return;
@ -138,7 +138,9 @@ function createItem(list: HTMLUListElement, suggestion: TermSuggestion) {
removeSelected(); removeSelected();
item.classList.add('autocomplete__item--selected'); item.classList.add('autocomplete__item--selected');
}); }
item.addEventListener('mouseover', onItemMouseOver);
item.addEventListener('mouseout', () => { item.addEventListener('mouseout', () => {
removeSelected(); removeSelected();
@ -148,7 +150,7 @@ function createItem(list: HTMLUListElement, suggestion: TermSuggestion) {
'mousemove', 'mousemove',
() => { () => {
ignoreMouseOver = false; ignoreMouseOver = false;
item.dispatchEvent(new CustomEvent('mouseover')); onItemMouseOver();
}, },
{ {
once: true, once: true,