diff --git a/src/components/forms/auto-complete/RuiAutoComplete.spec.ts b/src/components/forms/auto-complete/RuiAutoComplete.spec.ts index 26a37a0..86f9f5f 100644 --- a/src/components/forms/auto-complete/RuiAutoComplete.spec.ts +++ b/src/components/forms/auto-complete/RuiAutoComplete.spec.ts @@ -80,7 +80,12 @@ describe('autocomplete', () => { }, }); + await wrapper.find('input').trigger('focus'); + await nextTick(); + expect(document.body.querySelector('div[role=menu]')).toBeFalsy(); + // Open Menu Select + await wrapper.find('[data-id=activator]').trigger('focus'); await wrapper.find('[data-id=activator]').trigger('click'); await vi.delay(); await nextTick(); diff --git a/src/components/forms/auto-complete/RuiAutoComplete.vue b/src/components/forms/auto-complete/RuiAutoComplete.vue index ce49c5c..83bb179 100644 --- a/src/components/forms/auto-complete/RuiAutoComplete.vue +++ b/src/components/forms/auto-complete/RuiAutoComplete.vue @@ -417,7 +417,6 @@ watch(anyFocused, (focused) => { }); function onInputFocused() { - set(isOpen, true); set(focusedValueIndex, -1); if (get(shouldApplyValueAsSearch)) get(textInput)?.select(); @@ -460,7 +459,13 @@ function chipListener(item: (T extends string ? T : Record), index: number } function onEnter(event: KeyboardEvent) { - if (get(filteredOptions).length > 0 && get(highlightedIndex) > -1 && get(isOpen)) { + if (!get(isOpen)) { + set(isOpen, true); + event.preventDefault(); + return; + } + + if (get(filteredOptions).length > 0 && get(highlightedIndex) > -1) { applyHighlighted(); event.preventDefault(); }