Merge branch 'fix/r9-primitive-a11y' into fix/r9-form-and-primitives
frontend-quality-gates / merge / static checks (pull_request) Successful in 2m49s
frontend-quality-gates / merge / tests (pull_request) Successful in 15m8s
frontend-quality-gates / merge / browser tests (pull_request) Successful in 7m8s
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Skipped
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Skipped
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Skipped
frontend-quality-gates / external-vulnerability-provider (pull_request) Skipped
frontend-quality-gates / external-provenance-provider (pull_request) Skipped
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Skipped
frontend-quality-gates / deploy-promoted-release (pull_request) Skipped
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Skipped
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Skipped
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Skipped
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Skipped
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Skipped
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Skipped
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Skipped
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Skipped
frontend-quality-gates / main / self-tests and removal drills (pull_request) Skipped
frontend-quality-gates / merge / static checks (pull_request) Successful in 2m49s
frontend-quality-gates / merge / tests (pull_request) Successful in 15m8s
frontend-quality-gates / merge / browser tests (pull_request) Successful in 7m8s
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Skipped
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Skipped
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Skipped
frontend-quality-gates / external-vulnerability-provider (pull_request) Skipped
frontend-quality-gates / external-provenance-provider (pull_request) Skipped
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Skipped
frontend-quality-gates / deploy-promoted-release (pull_request) Skipped
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Skipped
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Skipped
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Skipped
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Skipped
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Skipped
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Skipped
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Skipped
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Skipped
frontend-quality-gates / main / self-tests and removal drills (pull_request) Skipped
This commit is contained in:
@@ -42,7 +42,11 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
|
||||
}}
|
||||
type="checkbox"
|
||||
/>
|
||||
<span>{label}</span>
|
||||
<span>
|
||||
{label}
|
||||
{/* 1112/05-13. The symbol as Field draws it; the state is on the input. */}
|
||||
{props.required ? <span aria-hidden="true"> *</span> : null}
|
||||
</span>
|
||||
</label>
|
||||
{description ? (
|
||||
<p className="ui-field__description" id={descriptionId}>
|
||||
|
||||
@@ -41,6 +41,7 @@ export const Dialog = forwardRef<HTMLDialogElement, DialogProps>(
|
||||
const dialogRef = useRef<HTMLDialogElement | null>(null);
|
||||
const previousFocusRef = useRef<HTMLElement | null>(null);
|
||||
const focusRestoreGenerationRef = useRef(0);
|
||||
const innerEscapeRef = useRef(false);
|
||||
const titleId = useId();
|
||||
const descriptionId = useId();
|
||||
useImperativeHandle(forwardedRef, () => dialogRef.current!, []);
|
||||
@@ -103,16 +104,26 @@ export const Dialog = forwardRef<HTMLDialogElement, DialogProps>(
|
||||
className={`ui-dialog ${className}`.trim()}
|
||||
onCancel={(event) => {
|
||||
event.preventDefault();
|
||||
// The Escape that fired this cancel closed an inner layer.
|
||||
if (innerEscapeRef.current) return;
|
||||
onClose();
|
||||
}}
|
||||
onClick={(event) => {
|
||||
if (event.target === event.currentTarget) onClose();
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
onClose();
|
||||
if (event.key !== "Escape") return;
|
||||
// 1112/05-11. A Menu, Popover or Tooltip inside handled this Escape
|
||||
// (it prevented the default): it closes that layer, not the Dialog.
|
||||
if (event.defaultPrevented) {
|
||||
innerEscapeRef.current = true;
|
||||
globalThis.setTimeout(() => {
|
||||
innerEscapeRef.current = false;
|
||||
}, 0);
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
onClose();
|
||||
}}
|
||||
ref={dialogRef}
|
||||
>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 1112/05-11. Whether an Escape is for a layer drawn over the page (a
|
||||
* Popover or a shown Tooltip) whose root is `root`. Not when it was pressed
|
||||
* inside a dialog that does not hold the layer: that Escape is the dialog's.
|
||||
* An Escape from the layer, from a dialog around it, or from no element
|
||||
* (focus on the body, as after a click in WebKit) is the layer's.
|
||||
*/
|
||||
export function escapeIsForLayer(event: KeyboardEvent, root: Element | null): boolean {
|
||||
const target = event.target;
|
||||
if (root === null || !(target instanceof Element) || root.contains(target)) {
|
||||
return true;
|
||||
}
|
||||
const dialog = target.closest("dialog");
|
||||
return dialog === null || dialog.contains(root);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useId, useRef, useState } from "react";
|
||||
|
||||
import { Button } from "./button.tsx";
|
||||
import { escapeIsForLayer } from "./escape-layer.ts";
|
||||
|
||||
export type PopoverProps = Readonly<{
|
||||
triggerLabel: string;
|
||||
@@ -12,6 +13,7 @@ export function Popover({ triggerLabel, children }: PopoverProps) {
|
||||
const rootRef = useRef<HTMLDivElement | null>(null);
|
||||
const triggerRef = useRef<HTMLButtonElement | null>(null);
|
||||
const contentId = useId();
|
||||
const triggerId = useId();
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
@@ -24,17 +26,25 @@ export function Popover({ triggerLabel, children }: PopoverProps) {
|
||||
triggerRef.current?.focus();
|
||||
}
|
||||
}
|
||||
// Capture phase, and the default prevented: the Escape closes this
|
||||
// layer only, not a Dialog around it (1112/05-11). An Escape pressed in
|
||||
// a Dialog this popover is not in is the Dialog's.
|
||||
function closeOnEscape(event: KeyboardEvent) {
|
||||
if (event.key === "Escape") {
|
||||
if (
|
||||
event.key === "Escape" &&
|
||||
!event.defaultPrevented &&
|
||||
escapeIsForLayer(event, rootRef.current)
|
||||
) {
|
||||
event.preventDefault();
|
||||
setOpen(false);
|
||||
triggerRef.current?.focus();
|
||||
}
|
||||
}
|
||||
document.addEventListener("pointerdown", closeOutside);
|
||||
document.addEventListener("keydown", closeOnEscape);
|
||||
document.addEventListener("keydown", closeOnEscape, true);
|
||||
return () => {
|
||||
document.removeEventListener("pointerdown", closeOutside);
|
||||
document.removeEventListener("keydown", closeOnEscape);
|
||||
document.removeEventListener("keydown", closeOnEscape, true);
|
||||
};
|
||||
}, [open]);
|
||||
|
||||
@@ -43,6 +53,7 @@ export function Popover({ triggerLabel, children }: PopoverProps) {
|
||||
<Button
|
||||
aria-controls={contentId}
|
||||
aria-expanded={open}
|
||||
id={triggerId}
|
||||
onClick={() => setOpen((current) => !current)}
|
||||
ref={triggerRef}
|
||||
variant="secondary"
|
||||
@@ -50,7 +61,12 @@ export function Popover({ triggerLabel, children }: PopoverProps) {
|
||||
{triggerLabel}
|
||||
</Button>
|
||||
{open ? (
|
||||
<div className="ui-popover__content" id={contentId} role="dialog">
|
||||
<div
|
||||
aria-labelledby={triggerId}
|
||||
className="ui-popover__content"
|
||||
id={contentId}
|
||||
role="dialog"
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -47,6 +47,9 @@ export const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(
|
||||
className="ui-field__input"
|
||||
id={controlId}
|
||||
ref={inputRef}
|
||||
// 1112/05-13. Required both ways, as TextField: the symbol
|
||||
// Field draws and the state on the input.
|
||||
required={required}
|
||||
type="search"
|
||||
value={value}
|
||||
/>
|
||||
|
||||
@@ -45,33 +45,52 @@ export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
|
||||
label={label}
|
||||
required={required}
|
||||
>
|
||||
{({ controlId, describedBy, invalid }) => (
|
||||
<>
|
||||
<textarea
|
||||
{...props}
|
||||
aria-describedby={describedBy}
|
||||
aria-invalid={invalid || undefined}
|
||||
className="ui-field__input ui-field__textarea"
|
||||
defaultValue={value === undefined ? defaultValue : undefined}
|
||||
id={controlId}
|
||||
maxLength={maxLength}
|
||||
onChange={(event) => {
|
||||
if (value === undefined) setUncontrolledValue(event.currentTarget.value);
|
||||
props.onChange?.(event);
|
||||
}}
|
||||
ref={ref}
|
||||
required={required}
|
||||
value={value}
|
||||
/>
|
||||
{remaining !== null ? (
|
||||
<output className="ui-field__counter">
|
||||
{maxLengthMessage
|
||||
? maxLengthMessage(remaining)
|
||||
: message("form.remaining", { count: remaining })}
|
||||
</output>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
{({ controlId, describedBy, invalid }) => {
|
||||
// 1112/05-17. The count describes the field; it is read when the
|
||||
// field is reached, not announced on every key. Reaching the limit
|
||||
// is announced once.
|
||||
const counterId = `${controlId}-counter`;
|
||||
const counterText =
|
||||
remaining === null
|
||||
? null
|
||||
: maxLengthMessage
|
||||
? maxLengthMessage(remaining)
|
||||
: message("form.remaining", { count: remaining });
|
||||
return (
|
||||
<>
|
||||
<textarea
|
||||
{...props}
|
||||
aria-describedby={
|
||||
[describedBy, counterText === null ? undefined : counterId]
|
||||
.filter(Boolean)
|
||||
.join(" ") || undefined
|
||||
}
|
||||
aria-invalid={invalid || undefined}
|
||||
className="ui-field__input ui-field__textarea"
|
||||
defaultValue={value === undefined ? defaultValue : undefined}
|
||||
id={controlId}
|
||||
maxLength={maxLength}
|
||||
onChange={(event) => {
|
||||
if (value === undefined) setUncontrolledValue(event.currentTarget.value);
|
||||
props.onChange?.(event);
|
||||
}}
|
||||
ref={ref}
|
||||
required={required}
|
||||
value={value}
|
||||
/>
|
||||
{counterText !== null ? (
|
||||
<>
|
||||
<span className="ui-field__counter" id={counterId}>
|
||||
{counterText}
|
||||
</span>
|
||||
<span aria-live="polite" className="visually-hidden">
|
||||
{remaining === 0 ? counterText : ""}
|
||||
</span>
|
||||
</>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}}
|
||||
</Field>
|
||||
);
|
||||
},
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
|
||||
@@ -79,14 +80,28 @@ function ToastRegion({
|
||||
dismiss(id: string): void;
|
||||
}>) {
|
||||
const { message } = useLocale();
|
||||
// 1112/05-14. Where focus was before it came into the toasts: closing the
|
||||
// last toast with its button gives focus back there, not to the body.
|
||||
const returnFocusRef = useRef<HTMLElement | null>(null);
|
||||
return (
|
||||
<section
|
||||
aria-label={message("toast.region")}
|
||||
aria-live="polite"
|
||||
className="ui-toast-region"
|
||||
onFocus={(event) => {
|
||||
const from = event.relatedTarget;
|
||||
if (from instanceof HTMLElement && !event.currentTarget.contains(from)) {
|
||||
returnFocusRef.current = from;
|
||||
}
|
||||
}}
|
||||
>
|
||||
{toasts.map((toast) => (
|
||||
<ToastItem dismiss={dismiss} key={toast.id} toast={toast} />
|
||||
<ToastItem
|
||||
dismiss={dismiss}
|
||||
key={toast.id}
|
||||
returnFocus={() => returnFocusRef.current}
|
||||
toast={toast}
|
||||
/>
|
||||
))}
|
||||
</section>
|
||||
);
|
||||
@@ -95,9 +110,11 @@ function ToastRegion({
|
||||
function ToastItem({
|
||||
toast,
|
||||
dismiss,
|
||||
returnFocus,
|
||||
}: Readonly<{
|
||||
toast: ToastEntry;
|
||||
dismiss(id: string): void;
|
||||
returnFocus(): HTMLElement | null;
|
||||
}>) {
|
||||
const { message } = useLocale();
|
||||
const [paused, setPaused] = useState(false);
|
||||
@@ -129,7 +146,21 @@ function ToastItem({
|
||||
</div>
|
||||
<IconButton
|
||||
accessibleName={message("action.closeNamed", { title: toast.title })}
|
||||
onClick={() => dismiss(toast.id)}
|
||||
onClick={(event) => {
|
||||
// The button goes away with its toast. Focus moves to the next
|
||||
// toast's close button, or back to where it came from.
|
||||
const item = event.currentTarget.closest("article");
|
||||
const items = item?.parentElement
|
||||
? [...item.parentElement.querySelectorAll(":scope > article")]
|
||||
: [];
|
||||
const index = item ? items.indexOf(item) : -1;
|
||||
const neighbour = items[index + 1] ?? items[index - 1];
|
||||
const next =
|
||||
neighbour?.querySelector("button") ??
|
||||
(returnFocus()?.isConnected ? returnFocus() : null);
|
||||
dismiss(toast.id);
|
||||
next?.focus();
|
||||
}}
|
||||
variant="ghost"
|
||||
>
|
||||
<CloseIcon />
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { cloneElement, useEffect, useId, useState } from "react";
|
||||
import { cloneElement, useEffect, useId, useRef, useState } from "react";
|
||||
|
||||
import { escapeIsForLayer } from "./escape-layer.ts";
|
||||
|
||||
export type TooltipProps = Readonly<{
|
||||
content: string;
|
||||
@@ -7,29 +9,55 @@ export type TooltipProps = Readonly<{
|
||||
|
||||
/**
|
||||
* Describes its focusable child (WCAG 1.4.13): the child carries
|
||||
* `aria-describedby`, and Escape hides the tooltip until the next hover or
|
||||
* focus.
|
||||
* `aria-describedby`, Escape hides the tooltip until the next hover or
|
||||
* focus, and the pointer can move onto the tooltip (primitives.css).
|
||||
*/
|
||||
export function Tooltip({ content, children }: TooltipProps) {
|
||||
const tooltipId = useId();
|
||||
const [dismissed, setDismissed] = useState(false);
|
||||
const [hovered, setHovered] = useState(false);
|
||||
const [focused, setFocused] = useState(false);
|
||||
const rootRef = useRef<HTMLSpanElement | null>(null);
|
||||
const shown = (hovered || focused) && !dismissed;
|
||||
useEffect(() => {
|
||||
if (dismissed) return;
|
||||
// Document level: a hovered trigger does not have keyboard focus.
|
||||
if (!shown) return;
|
||||
// Document level: a hovered trigger does not have keyboard focus. Capture
|
||||
// phase, and the default prevented: this Escape hides the tooltip only,
|
||||
// not a Dialog around it (1112/05-11). A tooltip that is not shown, or
|
||||
// one outside the Dialog the Escape was pressed in, leaves it alone.
|
||||
function dismissOnEscape(event: KeyboardEvent) {
|
||||
if (event.key === "Escape") setDismissed(true);
|
||||
if (
|
||||
event.key !== "Escape" ||
|
||||
event.defaultPrevented ||
|
||||
!escapeIsForLayer(event, rootRef.current)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
setDismissed(true);
|
||||
}
|
||||
document.addEventListener("keydown", dismissOnEscape);
|
||||
return () => document.removeEventListener("keydown", dismissOnEscape);
|
||||
}, [dismissed]);
|
||||
document.addEventListener("keydown", dismissOnEscape, true);
|
||||
return () => document.removeEventListener("keydown", dismissOnEscape, true);
|
||||
}, [shown]);
|
||||
const describedBy = [children.props["aria-describedby"], tooltipId]
|
||||
.filter(Boolean)
|
||||
.join(" ");
|
||||
return (
|
||||
<span
|
||||
className="ui-tooltip"
|
||||
onFocus={() => setDismissed(false)}
|
||||
onMouseEnter={() => setDismissed(false)}
|
||||
ref={rootRef}
|
||||
onBlur={(event) => {
|
||||
if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false);
|
||||
}}
|
||||
onFocus={() => {
|
||||
setFocused(true);
|
||||
setDismissed(false);
|
||||
}}
|
||||
onMouseEnter={() => {
|
||||
setHovered(true);
|
||||
setDismissed(false);
|
||||
}}
|
||||
onMouseLeave={() => setHovered(false)}
|
||||
>
|
||||
{cloneElement(children, { "aria-describedby": describedBy })}
|
||||
<span
|
||||
|
||||
@@ -53,7 +53,7 @@ export default function HomePage() {
|
||||
title={message("route.APP_HOME.title")}
|
||||
description={message("home.description")}
|
||||
/>
|
||||
<div className="readiness-grid" aria-label={message("home.readiness")}>
|
||||
<div className="readiness-grid" role="group" aria-label={message("home.readiness")}>
|
||||
{READINESS_ITEMS.map((item) => (
|
||||
<article className="ui-panel" key={item}>
|
||||
<h2>{message(`home.readiness.${item}.title`)}</h2>
|
||||
|
||||
@@ -516,9 +516,21 @@
|
||||
transition: opacity var(--duration-fast) var(--easing-standard);
|
||||
}
|
||||
|
||||
/* 1112/05-06. WCAG 1.4.13 hoverable: a shown tooltip takes the pointer,
|
||||
and the bridge below it covers the gap to the trigger, so moving onto it
|
||||
keeps .ui-tooltip hovered. A hidden one stays out of the pointer's way. */
|
||||
.ui-tooltip__content::before {
|
||||
position: absolute;
|
||||
inset-inline: 0;
|
||||
inset-block-start: 100%;
|
||||
block-size: var(--space-2);
|
||||
content: "";
|
||||
}
|
||||
|
||||
.ui-tooltip:focus-within .ui-tooltip__content,
|
||||
.ui-tooltip:hover .ui-tooltip__content {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.ui-progress,
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
padding-block: clamp(1rem, 5vw, 3.5rem) 0.5rem;
|
||||
}
|
||||
|
||||
[data-route-heading]:focus {
|
||||
/* 1112/05-02. Pointer navigation only: a keyboard user keeps the
|
||||
:focus-visible ring (base.css) on the heading each route move focuses. */
|
||||
[data-route-heading]:focus:not(:focus-visible) {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user