fix: autocomplete not being focused properly

This commit is contained in:
Freeplay 2023-06-23 17:30:50 -04:00
parent f101317f3c
commit 56cd2ea888
1 changed files with 7 additions and 2 deletions

View File

@ -19,8 +19,7 @@
> >
<FocusTrap <FocusTrap
v-model:active="isActive" v-model:active="isActive"
:initial-focus="() => $refs.content" :return-focus-on-deactivate="false"
:return-focus-on-deactivate="!noReturnFocus"
@deactivate="close" @deactivate="close"
> >
<div <div
@ -67,6 +66,8 @@
]" ]"
:style="{ zIndex }" :style="{ zIndex }"
@click.self="onBgClick" @click.self="onBgClick"
v-focus
tabindex="-1"
> >
<slot :max-height="maxHeight" :type="type"></slot> <slot :max-height="maxHeight" :type="type"></slot>
</div> </div>
@ -179,6 +180,7 @@ let transitionDuration = $computed(() =>
let contentClicking = false; let contentClicking = false;
const focusedElement = document.activeElement;
function close(ev, opts: { useSendAnimation?: boolean } = {}) { function close(ev, opts: { useSendAnimation?: boolean } = {}) {
// removeEventListener("popstate", close); // removeEventListener("popstate", close);
// if (props.preferType == "dialog") { // if (props.preferType == "dialog") {
@ -192,6 +194,9 @@ function close(ev, opts: { useSendAnimation?: boolean } = {}) {
if (props.src) props.src.style.pointerEvents = "auto"; if (props.src) props.src.style.pointerEvents = "auto";
showing = false; showing = false;
emit("close"); emit("close");
if (!props.noReturnFocus) {
focusedElement.focus();
}
} }
function onBgClick() { function onBgClick() {