fix: fix focus behaviour in tags selector

This commit is contained in:
Alex Grozav 2023-07-26 15:57:25 +03:00
parent 134938dcc9
commit 682ba0bc93

View file

@ -14,7 +14,6 @@
multiple multiple
:allowCreate="createEnabled" :allowCreate="createEnabled"
:reserve-keyword="false" :reserve-keyword="false"
default-first-option
ref="selectRef" ref="selectRef"
loading-text="..." loading-text="..."
popper-class="tags-dropdown" popper-class="tags-dropdown"
@ -178,12 +177,12 @@ export default defineComponent({
function onBusFocus() { function onBusFocus() {
focusOnInput(); focusOnInput();
focusOnTopOption(); focusFirstOption();
} }
function filterOptions(value = '') { function filterOptions(value = '') {
filter.value = value.trim(); filter.value = value.trim();
void nextTick(() => focusOnTopOption()); nextTick(() => focusFirstOption());
} }
async function onCreate() { async function onCreate() {
@ -225,15 +224,14 @@ export default defineComponent({
} }
} }
function focusOnTopOption() { async function focusFirstOption() {
// focus on create option // focus on create option
if (createRef.value?.focus) { if (createRef.value?.focus) {
createRef.value.focus(); createRef.value.focus();
} }
// focus on top option after filter // focus on top option after filter
else if (tagRefs.value?.[0]?.$el.focus) { else if (tagRefs.value?.[0]?.$el.focus) {
tagRefs.value[0].$el.focus(); tagRefs.value[0].$el.dispatchEvent(new Event('mouseenter'));
console.log('focusing', tagRefs.value[0].$el);
} }
} }