();
watch(isOpen, () => {
if (!isOpen.value) return;
const { offsetTop, offsetLeft: x, offsetWidth: width, offsetHeight } = element.value!;
const y = offsetTop + offsetHeight + 8;
position.value = { x, y, width };
+ search.value = '';
+});
+
+watchEffect(() => {
+ searchInputRef.value?.focus();
+});
+
+const filteredOptions = computed(() => {
+ if (!search.value) return options;
+ return options.filter((option) => option.toLowerCase().includes(search.value.toLowerCase()));
});
function onClickOutside(event: MouseEvent) {
@@ -40,8 +52,8 @@ function onKeydown(event: KeyboardEvent) {
if (document.activeElement?.getAttribute('data-select-option')) {
const element =
event.key === 'ArrowDown'
- ? document.activeElement.nextSibling
- : document.activeElement.previousSibling;
+ ? document.activeElement.nextElementSibling
+ : document.activeElement.previousElementSibling;
(element as HTMLElement)?.focus();
} else {
(document.querySelector('[data-select-option]') as HTMLElement | undefined)?.focus();
@@ -93,11 +105,17 @@ onUnmounted(() => {
+