Skip to content
This repository was archived by the owner on Apr 17, 2022. It is now read-only.

Commit 8cd54bc

Browse files
committed
fix: Tab index reset after date is selected (fixes #115)
1 parent 249b749 commit 8cd54bc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Vue3DatePicker/Vue3DatePicker.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<slot :name="slot" v-bind="args" />
3737
</template>
3838
</DatepickerInput>
39+
<span tabindex="-1" ref="focusRef"></span>
3940
<teleport :to="teleport" :disabled="inline" v-if="isOpen">
4041
<DatepickerMenu
4142
v-if="isOpen"
@@ -148,6 +149,7 @@
148149
const modelValueMap = toRef(props, 'modelValue');
149150
const dpMenuRef = ref(null);
150151
const inputRef = ref(null);
152+
const focusRef = ref<HTMLElement | null>(null);
151153
provide('autoApply', props.autoApply);
152154
const formatLocaleRef = computed(() => props.formatLocale);
153155
provide('formatLocale', formatLocaleRef);
@@ -387,6 +389,7 @@
387389
if (inputRef.value) {
388390
(inputRef.value as { unFocus: () => void }).unFocus();
389391
}
392+
setSoftFocus();
390393
}
391394
};
392395
@@ -408,6 +411,13 @@
408411
}
409412
};
410413
414+
// When menu is close, allows user interaction via keyboard down the DOM tree, focus the span el after dp
415+
const setSoftFocus = (): void => {
416+
if (focusRef.value) {
417+
focusRef.value.focus({ preventScroll: true });
418+
}
419+
};
420+
411421
onClickOutside(dpMenuRef, inputRef, closeMenu);
412422
413423
defineExpose({

0 commit comments

Comments
 (0)