combobox: move outer click handlers to onMount
This commit is contained in:
@@ -310,27 +310,6 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (browser) {
|
|
||||||
// update picker position on window resize
|
|
||||||
window.addEventListener('resize', updatePickerRect);
|
|
||||||
|
|
||||||
// add window click listener to close picker
|
|
||||||
window.addEventListener('click', (e) => {
|
|
||||||
if (!searchContainer || !pickerContainer) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
searchContainer.contains(e.target as Node) ||
|
|
||||||
pickerContainer.contains(e.target as Node)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
closePicker();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// when the value (or, in some circumstances, highlighted item) changes, update the search input
|
// when the value (or, in some circumstances, highlighted item) changes, update the search input
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (!searchInput) return;
|
if (!searchInput) return;
|
||||||
@@ -357,9 +336,30 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
// set initial picker position on load
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
updatePickerRect();
|
updatePickerRect();
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
// update picker position on window resize
|
||||||
|
window.addEventListener('resize', updatePickerRect);
|
||||||
|
|
||||||
|
// add window click listener to close picker
|
||||||
|
window.addEventListener('click', (e) => {
|
||||||
|
if (!searchContainer || !pickerContainer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
searchContainer.contains(e.target as Node) ||
|
||||||
|
pickerContainer.contains(e.target as Node) ||
|
||||||
|
!open
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
closePicker();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user