swarm ui: landmarks, a skip link, a page heading, named repeated buttons and a log role on the terminal
The shell now has a main landmark that takes the focus when a page opens, a skip link as the first Tab stop, a labelled nav, aria-current on the active tab, and a hidden h1 with the page's name (no page drew one). The tab close button and tab link get a visible focus ring and a larger target. Repeated edit, remove, delete, fire now, pause, duplicate buttons and the icon-only terminal, expand and close badges get a name that says what they act on (Button gains ariaLabel). A badge can be pressed (aria-pressed), used for the internet modes and the SSH target form, whose fake tablist is now a labelled group. The terminal is a focusable role=log with live announcements off, and a latest badge scrolls back to the newest row once the operator has scrolled up and the terminal has stopped following.
This commit is contained in:
parent
1ca82b3e09
commit
c9e6cd2e61
2 changed files with 218 additions and 17 deletions
|
|
@ -262,10 +262,36 @@
|
|||
all: unset;
|
||||
cursor: pointer;
|
||||
line-height: 1;
|
||||
padding: 0.1em 0.3em;
|
||||
padding: 0.25em 0.45em;
|
||||
border-radius: 0.2em;
|
||||
color: var(--muted);
|
||||
}
|
||||
/* `all: unset` drops the browser's focus ring, and so does the tab link's
|
||||
own reset, so both draw one. */
|
||||
.shell-tab-close:focus-visible,
|
||||
.shell-tab-link:focus-visible {
|
||||
outline: 2px solid var(--purple);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
/* A skip link, drawn only while it has the keyboard focus. */
|
||||
.shell-skip-link {
|
||||
position: absolute;
|
||||
left: 0.5em;
|
||||
top: -4em;
|
||||
z-index: 100;
|
||||
padding: 0.5em 1em;
|
||||
border-radius: 0.3em;
|
||||
background: var(--bg-elev);
|
||||
color: var(--fg);
|
||||
border: 1px solid var(--purple);
|
||||
}
|
||||
.shell-skip-link:focus {
|
||||
top: 0.5em;
|
||||
}
|
||||
/* The page container takes the focus when a page opens, and is not a control. */
|
||||
.shell-body:focus {
|
||||
outline: none;
|
||||
}
|
||||
.shell-tab-close:hover {
|
||||
color: var(--fg);
|
||||
background: color-mix(in srgb, var(--fg) 10%, transparent);
|
||||
|
|
|
|||
|
|
@ -120,7 +120,11 @@ function NavLink({
|
|||
textRef: (el: HTMLSpanElement | null) => void;
|
||||
}) {
|
||||
return (
|
||||
<Link href={href} className="shell-nav-link">
|
||||
<Link
|
||||
href={href}
|
||||
className="shell-nav-link"
|
||||
aria-current={active ? "page" : undefined}
|
||||
>
|
||||
{/* Touch target (min-height) lives on the <a> so the whole row is
|
||||
tappable. The underline lives on the shared
|
||||
`.shell-nav-indicator`, not here — this span is still what
|
||||
|
|
@ -216,6 +220,7 @@ function DynamicTabLink({
|
|||
<Link
|
||||
href={href}
|
||||
className="shell-tab-link"
|
||||
aria-current={active ? "page" : undefined}
|
||||
draggable={false}
|
||||
title={onRename === undefined ? undefined : "double click to rename"}
|
||||
onDblClick={
|
||||
|
|
@ -249,6 +254,7 @@ export function Shell({ children }: { children: ComponentChildren }) {
|
|||
const swarmName = useSwarmName();
|
||||
const [location] = useLocation();
|
||||
const navRef = useRef<HTMLElement | null>(null);
|
||||
const mainRef = useRef<HTMLElement | null>(null);
|
||||
const textRefs = useRef<Record<string, HTMLSpanElement | null>>({});
|
||||
const [indicator, setIndicator] = useState<IndicatorRect | null>(null);
|
||||
// The nav-item index the indicator is currently sitting at (or mid-hop
|
||||
|
|
@ -409,6 +415,17 @@ export function Shell({ children }: { children: ComponentChildren }) {
|
|||
document.title = pageLabel ? `${pageLabel} · ${brand}` : brand;
|
||||
}, [brand, pageLabel]);
|
||||
|
||||
// A new page starts at the top for the keyboard and a screen reader: the
|
||||
// focus goes to the page's container, not left on the link that was used.
|
||||
const firstPage = useRef(true);
|
||||
useEffect(() => {
|
||||
if (firstPage.current) {
|
||||
firstPage.current = false;
|
||||
return;
|
||||
}
|
||||
mainRef.current?.focus({ preventScroll: true });
|
||||
}, [location]);
|
||||
|
||||
// Same value the indicator itself is drawn with, including mid-sweep —
|
||||
// the brand text rides the identical hop sequence rather than
|
||||
// computing its own, so "the header's accent" reads as one thing
|
||||
|
|
@ -417,6 +434,18 @@ export function Shell({ children }: { children: ComponentChildren }) {
|
|||
|
||||
return (
|
||||
<div class={"shell" + (isFullBleedRoute(location) ? " shell-full" : "")}>
|
||||
<a
|
||||
class="shell-skip-link"
|
||||
href="#main"
|
||||
onClick={(e) => {
|
||||
// A plain hash would hand the click to the router; move the focus
|
||||
// here instead.
|
||||
e.preventDefault();
|
||||
mainRef.current?.focus();
|
||||
}}
|
||||
>
|
||||
skip to content
|
||||
</a>
|
||||
<header class="shell-header">
|
||||
<Link href="/" class="shell-brand-link">
|
||||
<span
|
||||
|
|
@ -434,7 +463,7 @@ export function Shell({ children }: { children: ComponentChildren }) {
|
|||
{brand}
|
||||
</span>
|
||||
</Link>
|
||||
<nav class="shell-nav" ref={navRef}>
|
||||
<nav class="shell-nav" aria-label="main" ref={navRef}>
|
||||
{navItems.map((item) => (
|
||||
<NavLink
|
||||
key={item.href}
|
||||
|
|
@ -522,14 +551,23 @@ export function Shell({ children }: { children: ComponentChildren }) {
|
|||
</header>
|
||||
{/* Keyed by route so it remounts (and replays its entrance
|
||||
animation) on every navigation — see the file-top comment. */}
|
||||
<div
|
||||
<main
|
||||
id="main"
|
||||
tabIndex={-1}
|
||||
ref={mainRef}
|
||||
class={
|
||||
"shell-body" + (isFullBleedRoute(location) ? " shell-body-full" : "")
|
||||
}
|
||||
key={location}
|
||||
>
|
||||
{/* The page's name for a screen reader. Only the start page draws an
|
||||
`<h1>` of its own (the swarm's name), so it gets no second one;
|
||||
the document title is the only other place the name shows. */}
|
||||
{location !== "/" && (
|
||||
<h1 class="ui-visually-hidden">{pageLabel ?? brand}</h1>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue