fix(ui): improve keyboard access and add headed checks
This commit is contained in:
1 parent
e202d250ea
commit
cfd4afd894
14 files changed
+123
-20
No files matched your search
@@ -27,6 +27,12 @@ const emit = defineEmits<{ newTask: [] }>();
|
||||
|
||||
const router = useRouter();
|
||||
const open = ref(false);
|
||||
let openedPath = router.currentRoute.value.path;
|
||||
function onCloseAutoFocus(event: Event): void {
|
||||
if (router.currentRoute.value.path === openedPath) return;
|
||||
event.preventDefault();
|
||||
document.getElementById("main-content")?.focus({ preventScroll: true });
|
||||
}
|
||||
|
||||
interface TaskEntry {
|
||||
id: number | string;
|
||||
@@ -54,7 +60,7 @@ async function loadEntries(): Promise<void> {
|
||||
}
|
||||
|
||||
watch(open, (value) => {
|
||||
if (value) void loadEntries();
|
||||
if (value) { openedPath = router.currentRoute.value.path; void loadEntries(); }
|
||||
});
|
||||
|
||||
function go(path: string): void {
|
||||
@@ -102,7 +108,7 @@ onUnmounted(() => document.removeEventListener("keydown", onGlobalKeydown));
|
||||
<span class="max-lg:hidden">Jump to</span>
|
||||
<Kbd class="ml-auto max-lg:hidden">{{ shortcut }}</Kbd>
|
||||
</Button>
|
||||
<CommandDialog v-model:open="open" title="Jump to" description="Find a page, task or workflow.">
|
||||
<CommandDialog @close-auto-focus="onCloseAutoFocus" v-model:open="open" title="Jump to" description="Find a page, task or workflow.">
|
||||
<CommandInput placeholder="Find a page, task or workflow" />
|
||||
<CommandList>
|
||||
<CommandEmpty>No matches.</CommandEmpty>
|
||||
|
||||
@@ -16,6 +16,13 @@ const props = defineProps<{ hidden: string[] }>();
|
||||
|
||||
const route = useRoute();
|
||||
const open = ref(false);
|
||||
let openedPath = route.path;
|
||||
watch(open, (value) => { if (value) openedPath = route.path; });
|
||||
function onCloseAutoFocus(event: Event): void {
|
||||
if (route.path === openedPath) return;
|
||||
event.preventDefault();
|
||||
document.getElementById("main-content")?.focus({ preventScroll: true });
|
||||
}
|
||||
const links = computed(() =>
|
||||
navTree(props.hidden).flatMap((node): NavEntry[] => (node.kind === "link" ? [node.entry] : [])),
|
||||
);
|
||||
@@ -39,7 +46,7 @@ watch(() => route.path, () => (open.value = false));
|
||||
<Menu aria-hidden="true" />
|
||||
</Button>
|
||||
</SheetTrigger>
|
||||
<SheetContent side="left" class="w-64 gap-0 p-0">
|
||||
<SheetContent @close-auto-focus="onCloseAutoFocus" side="left" class="w-64 gap-0 p-0">
|
||||
<SheetHeader class="border-b px-4 py-3">
|
||||
<SheetTitle class="flex items-center gap-2"><Logo /><BrandName /></SheetTitle>
|
||||
</SheetHeader>
|
||||
|
||||
@@ -16,7 +16,7 @@ const props = withDefaults(defineProps<DialogRootProps & {
|
||||
description: 'Search for a command to run...',
|
||||
showCloseButton: false,
|
||||
})
|
||||
const emits = defineEmits<DialogRootEmits>()
|
||||
const emits = defineEmits<DialogRootEmits & { closeAutoFocus: [event: Event] }>()
|
||||
|
||||
const forwarded = useForwardPropsEmits(props, emits)
|
||||
</script>
|
||||
@@ -26,6 +26,7 @@ const forwarded = useForwardPropsEmits(props, emits)
|
||||
<DialogContent
|
||||
:class="cn('rounded-xl! top-1/3 translate-y-0 overflow-hidden p-0', props.class)"
|
||||
:show-close-button="showCloseButton"
|
||||
@close-auto-focus="emits('closeAutoFocus', $event)"
|
||||
>
|
||||
<DialogHeader class="sr-only">
|
||||
<DialogTitle>{{ title }}</DialogTitle>
|
||||
|
||||
@@ -44,7 +44,7 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
||||
v-bind="{ ...$attrs, ...forwarded }"
|
||||
:class="
|
||||
cn(
|
||||
'bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 ring-foreground/10 grid max-w-[calc(100%-2rem)] gap-4 rounded-xl p-4 text-sm ring-1 duration-100 sm:max-w-sm fixed top-1/2 left-1/2 z-50 w-full -translate-x-1/2 -translate-y-1/2 outline-none',
|
||||
'bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 ring-foreground/10 grid max-h-[calc(100dvh-2rem)] overflow-y-auto max-w-[calc(100%-2rem)] gap-4 rounded-xl p-4 text-sm ring-1 duration-100 sm:max-w-sm fixed top-1/2 left-1/2 z-50 w-full -translate-x-1/2 -translate-y-1/2 outline-none',
|
||||
props.class,
|
||||
)
|
||||
"
|
||||
|
||||
Reference in new issue
Block a user