fix(ui): improve keyboard access and add headed checks

This commit is contained in:
sam committed 2026-10-19 01:45:20 +11:00
1 parent e202d250ea
commit cfd4afd894
14 files changed
+123 -20

No files matched your search

+12 -2
View File
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, onMounted, watch } from "vue";
import { computed, nextTick, onMounted, ref, watch } from "vue";
import { useRoute } from "vue-router";
import AccountEntry from "@/accounts/AccountEntry.vue";
@@ -19,6 +19,15 @@ const session = useSessionStore();
const route = useRoute();
const workflowsPage = computed(() => route.path === "/workflows");
const hidden = computed(() => hiddenPaths(session.sections));
const main = ref<HTMLElement | null>(null);
watch(() => route.path, () => {
const scope = route.meta.org ? "Organisation" : route.meta.settings ? "Instance" : "";
document.title = [route.meta.label || "Page not found", scope, "Archie"].filter(Boolean).join(" | ");
}, { immediate: true });
watch(() => route.path, async () => {
await nextTick();
main.value?.focus({ preventScroll: true });
}, { flush: "post" });
onMounted(() => {void accounts.load();});
watch(() => accounts.status?.user, (user) => {
@@ -47,8 +56,9 @@ watch(() => accounts.status?.user, (user) => {
class="flex min-h-dvh flex-col bg-[var(--workspace)]"
:class="workflowsPage && 'max-md:h-dvh'"
>
<a href="#main-content" class="sr-only focus:not-sr-only focus:fixed focus:top-2 focus:left-4 focus:z-[60] focus:rounded-md focus:bg-card focus:px-3 focus:py-2">Skip to main content</a>
<Topbar :hidden="hidden" />
<main class="w-full flex-1 px-6 py-5 max-lg:p-4"
<main id="main-content" ref="main" tabindex="-1" class="scroll-mt-16 w-full flex-1 px-6 py-5 max-lg:p-4"
:class="workflowsPage ? 'max-md:flex max-md:min-h-0 max-md:flex-col' : 'max-md:pb-24'">
<!--
Keyed on the path and its parameters but not the query: a query-only
+2
View File
@@ -114,6 +114,8 @@ function choose(index: number): void {
}
function onKeydown(event: KeyboardEvent): void {
// Safari may end composition before delivering its confirming Enter.
if (event.key === "Enter" && (event.isComposing || event.keyCode === 229)) return;
const plain = !event.shiftKey && !event.ctrlKey && !event.metaKey;
if (isCommandMenuOpen.value && commandMatches.value.length) {
// A command typed in full is sent rather than completed, so Enter never
@@ -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>
+8 -1
View File
@@ -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,
)
"