add the focus trap thingies again

This commit is contained in:
Freeplay 2023-04-28 19:57:19 -04:00
parent 6498a90dc1
commit 3be2147397
4 changed files with 380 additions and 382 deletions

View File

@ -1,4 +1,5 @@
<template> <template>
<FocusTrap v-bind:active="isActive">
<div <div
class="omfetrab" class="omfetrab"
:class="['s' + size, 'w' + width, 'h' + height, { asDrawer }]" :class="['s' + size, 'w' + width, 'h' + height, { asDrawer }]"
@ -152,6 +153,7 @@
</button> </button>
</div> </div>
</div> </div>
</FocusTrap>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@ -171,6 +173,7 @@ import { deviceKind } from "@/scripts/device-kind";
import { emojiCategories, instance } from "@/instance"; import { emojiCategories, instance } from "@/instance";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
import { FocusTrap } from 'focus-trap-vue';
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{

View File

@ -1,8 +1,8 @@
<template> <template>
<div> <FocusTrap v-bind:active="isActive">
<div tabindex="-1" v-focus>
<div <div
ref="itemsEl" ref="itemsEl"
v-hotkey="keymap"
class="rrevdjwt _popup _shadow" class="rrevdjwt _popup _shadow"
:class="{ center: align === 'center', asDrawer }" :class="{ center: align === 'center', asDrawer }"
:style="{ :style="{
@ -18,7 +18,6 @@
</span> </span>
<span <span
v-else-if="item.type === 'pending'" v-else-if="item.type === 'pending'"
:tabindex="i"
class="pending item" class="pending item"
> >
<span><MkEllipsis /></span> <span><MkEllipsis /></span>
@ -26,7 +25,6 @@
<MkA <MkA
v-else-if="item.type === 'link'" v-else-if="item.type === 'link'"
:to="item.to" :to="item.to"
:tabindex="i"
class="_button item" class="_button item"
@click.passive="close(true)" @click.passive="close(true)"
@mouseenter.passive="onItemMouseEnter(item)" @mouseenter.passive="onItemMouseEnter(item)"
@ -59,7 +57,6 @@
:href="item.href" :href="item.href"
:target="item.target" :target="item.target"
:download="item.download" :download="item.download"
:tabindex="i"
class="_button item" class="_button item"
@click="close(true)" @click="close(true)"
@mouseenter.passive="onItemMouseEnter(item)" @mouseenter.passive="onItemMouseEnter(item)"
@ -84,7 +81,6 @@
</a> </a>
<button <button
v-else-if="item.type === 'user' && !items.hidden" v-else-if="item.type === 'user' && !items.hidden"
:tabindex="i"
class="_button item" class="_button item"
:class="{ active: item.active }" :class="{ active: item.active }"
:disabled="item.active" :disabled="item.active"
@ -101,7 +97,6 @@
</button> </button>
<span <span
v-else-if="item.type === 'switch'" v-else-if="item.type === 'switch'"
:tabindex="i"
class="item" class="item"
@mouseenter.passive="onItemMouseEnter(item)" @mouseenter.passive="onItemMouseEnter(item)"
@mouseleave.passive="onItemMouseLeave(item)" @mouseleave.passive="onItemMouseLeave(item)"
@ -116,7 +111,6 @@
</span> </span>
<button <button
v-else-if="item.type === 'parent'" v-else-if="item.type === 'parent'"
:tabindex="i"
class="_button item parent" class="_button item parent"
:class="{ childShowing: childShowingItem === item }" :class="{ childShowing: childShowingItem === item }"
@mouseenter="showChildren(item, $event)" @mouseenter="showChildren(item, $event)"
@ -140,7 +134,6 @@
</button> </button>
<button <button
v-else-if="!item.hidden" v-else-if="!item.hidden"
:tabindex="i"
class="_button item" class="_button item"
:class="{ danger: item.danger, active: item.active }" :class="{ danger: item.danger, active: item.active }"
:disabled="item.active" :disabled="item.active"
@ -186,6 +179,7 @@
/> />
</div> </div>
</div> </div>
</FocusTrap>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@ -229,12 +223,6 @@ let items2: InnerMenuItem[] = $ref([]);
let child = $ref<InstanceType<typeof XChild>>(); let child = $ref<InstanceType<typeof XChild>>();
let keymap = computed(() => ({
"up|k|shift+tab": focusUp,
"down|j|tab": focusDown,
esc: close,
}));
let childShowingItem = $ref<MenuItem | null>(); let childShowingItem = $ref<MenuItem | null>();
watch( watch(

View File

@ -35,6 +35,8 @@
: 'none', : 'none',
'--transformOrigin': transformOrigin, '--transformOrigin': transformOrigin,
}" }"
tabindex="-1"
v-focus
> >
<div <div
class="_modalBg data-cy-bg" class="_modalBg data-cy-bg"
@ -50,6 +52,7 @@
@mousedown="onBgClick" @mousedown="onBgClick"
@contextmenu.prevent.stop="() => {}" @contextmenu.prevent.stop="() => {}"
></div> ></div>
<focus-trap v-model:active="isActive">
<div <div
ref="content" ref="content"
:class="[ :class="[
@ -61,6 +64,7 @@
> >
<slot :max-height="maxHeight" :type="type"></slot> <slot :max-height="maxHeight" :type="type"></slot>
</div> </div>
</focus-trap>
</div> </div>
</Transition> </Transition>
</template> </template>

View File

@ -3,8 +3,10 @@
ref="modal" ref="modal"
:prefer-type="'dialog'" :prefer-type="'dialog'"
@click="onBgClick" @click="onBgClick"
@keyup.esc="$emit('close')"
@closed="$emit('closed')" @closed="$emit('closed')"
> >
<focus-trap v-model:active="isActive">
<div <div
ref="rootEl" ref="rootEl"
class="ebkgoccj" class="ebkgoccj"
@ -51,6 +53,7 @@
<slot :width="bodyWidth" :height="bodyHeight"></slot> <slot :width="bodyWidth" :height="bodyHeight"></slot>
</div> </div>
</div> </div>
</focus-trap>
</MkModal> </MkModal>
</template> </template>