fix(ui): scale touch targets to the pointer, not the window width
A coarse-pointer-only floor keeps switches, tab triggers and scrolled nav strips from being deformed on a phone, and the topbar reveals the current section after a route change.
This commit is contained in:
5 files changed
+26
-8
No files matched your search
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { computed, onMounted, watch } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
|
||||
import { activeNavPath, navTree, type NavEntry } from "@/lib/nav";
|
||||
@@ -11,6 +11,18 @@ const links = computed(() =>
|
||||
navTree(props.hidden).flatMap((node): NavEntry[] => (node.kind === "link" ? [node.entry] : [])),
|
||||
);
|
||||
const activePath = computed(() => activeNavPath(route.path));
|
||||
|
||||
// The strip scrolls sideways on a narrow window, so the current section can sit
|
||||
// outside it. Centre it after each route change; block:"nearest" keeps it from
|
||||
// scrolling the page too.
|
||||
function revealActive(): void {
|
||||
document
|
||||
.querySelector('nav[aria-label="Sections"] [aria-current="page"]')
|
||||
?.scrollIntoView({ inline: "center", block: "nearest" });
|
||||
}
|
||||
|
||||
onMounted(revealActive);
|
||||
watch(activePath, revealActive, { flush: "post" });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -45,7 +45,7 @@ const items = computed(() =>
|
||||
:aria-current="route.path === item.path ? 'page' : undefined"
|
||||
:class="
|
||||
cn(
|
||||
'flex h-8 items-center rounded-md px-3 text-[13px] whitespace-nowrap text-muted-foreground transition-colors hover:bg-secondary hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring',
|
||||
'flex h-8 shrink-0 items-center rounded-md px-3 text-[13px] whitespace-nowrap text-muted-foreground transition-colors hover:bg-secondary hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring',
|
||||
route.path === item.path &&
|
||||
'bg-secondary font-medium text-foreground',
|
||||
)
|
||||
|
||||
+10
-4
@@ -257,23 +257,29 @@
|
||||
/* Fingers need 44px targets (WCAG 2.5.5). Min sizes rather than heights, so
|
||||
a component's own sizing still applies wherever it is already larger,
|
||||
and inline links in prose are unaffected because min sizes do not apply
|
||||
to inline boxes. */
|
||||
@media (pointer: coarse), (width < 48rem) {
|
||||
to inline boxes. Only a coarse pointer means a finger: a narrow window on
|
||||
a desktop still uses a mouse. Switches and tab triggers are exempt because
|
||||
they shrink their own box (a switch draws its hit area with ::after, tabs
|
||||
share a fixed-height strip), so a min size deforms them instead. */
|
||||
@media (pointer: coarse) {
|
||||
:where(
|
||||
button,
|
||||
button:not([role="switch"], [role="tab"]),
|
||||
a[href],
|
||||
summary,
|
||||
select,
|
||||
textarea,
|
||||
input:not([type="checkbox"], [type="radio"], [type="hidden"]),
|
||||
[role="button"],
|
||||
[role="tab"],
|
||||
[role="menuitem"],
|
||||
[role="option"]
|
||||
) {
|
||||
min-height: 44px;
|
||||
min-width: 44px;
|
||||
}
|
||||
/* Tabs fill their list, so the list carries the touch height instead. */
|
||||
[data-slot="tabs-list"] {
|
||||
min-height: 44px;
|
||||
}
|
||||
}
|
||||
/* An accessibility invariant, not a nicety: nothing animates for someone
|
||||
who has asked it not to. */
|
||||
|
||||
Reference in new issue
Block a user