fix(design-system): 공통 primitive의 키보드·보조기술 동작을 약속대로 맞춘다
공통 primitive가 디자인 시스템 설계 8.1·8.2절과 WCAG 2.2 AA 약속을 어긴다. - Popover가 이름 없는 role="dialog"를 그린다(1112/05-10). - Dialog 안의 Menu·Popover·Tooltip에서 Escape를 누르면 Dialog까지 닫힌다. Dialog가 안쪽이 처리한 Escape를 보지 않는다(05-11). - SearchField는 required 기호만, Checkbox는 상태만 있다(05-13). - Toast를 닫기 버튼으로 닫으면 포커스가 body로 떨어진다(05-14). - TextArea 글자 수가 <output>(암묵 status)이라 글자마다 발표되고 입력과 이어지지 않는다(05-17). - 라우트 h1의 :focus outline 제거가 layer 순서로 키보드 :focus-visible 표시까지 지운다(05-02). Tooltip이 pointer-events: none과 틈 때문에 포인터를 설명 위로 옮기면 사라진다(1.4.13, 05-06). - 홈 readiness 목록이 role 없는 div에 aria-label을 단다(05-15). - fe-a11y·fe-ux 스킬이 제출 실패 때 오류 요약으로 포커스가 간다고 적는다. 코드는 첫 오류 필드로 보낸다(05-09). 고른 방법: Popover는 trigger id로 이름을 받는다. Popover·Tooltip은 Escape를 capture 단계에서 받아 preventDefault하고, Dialog는 기본 동작이 막힌 Escape(과 그 뒤 cancel)를 넘긴다. Tooltip은 보일 때(hover·focus)만 Escape를 가진다. 숨은 tooltip이 다른 Dialog의 Escape를 막지 않게 하려는 것이다. Toast 닫기는 다음 toast의 닫기 버튼, 없으면 toast로 들어오기 전 요소로 포커스를 돌린다. TextArea 글자 수는 aria-describedby로 잇고 0에 닿을 때만 따로 발표한다. h1은 :focus:not(:focus-visible)만 outline을 지운다. Tooltip은 보일 때만 포인터를 받고 ::before 다리로 틈을 메운다. 버린 대안: Dialog가 안쪽 layer 목록을 들고 Escape를 나누기(primitive끼리 묶인다). 위험·한계: native <dialog>가 막힌 keydown 뒤에도 cancel을 쏘는지는 브라우저마다 다를 수 있어, Dialog는 같은 task의 cancel 하나를 넘긴다. Toast가 돌려줄 요소가 지워졌으면 포커스를 옮기지 않는다. 시각 골든이 바뀌는지는 desktop test:visual로 본다. 검증: 새 component 시험(tests/component/design-system-a11y.test.tsx, starter-pages), e2e(app-shell focus ring, 세 엔진), storybook(tooltip hover)의 RED·GREEN은 desktop에서 돌려 PR 본문에 적는다. Refs: 1112/05-02, 1112/05-06, 1112/05-09, 1112/05-10, 1112/05-11, 1112/05-13, 1112/05-14, 1112/05-15, 1112/05-17
This commit is contained in:
@@ -51,7 +51,7 @@ paths:
|
||||
|
||||
폼
|
||||
|
||||
- [ ] label·설명·오류가 같은 ID 체계와 `aria-describedby`로 연결된다(M5). required는 기호와 programmatic 상태를 함께 가진다. 제출 실패 시 오류 요약으로 포커스가 간다. — DS 8.3절
|
||||
- [ ] label·설명·오류가 같은 ID 체계와 `aria-describedby`로 연결된다(M5). required는 기호와 programmatic 상태를 함께 가진다. 입력 오류로 제출이 실패하면 첫 오류 필드로 포커스가 가고, 오류 요약은 그 필드들로 가는 링크다(`src/presentation/forms/use-app-form.ts` `focusFirstError`). 입력 오류가 아닌 실패는 feedback 자리가 포커스를 받는다. — DS 8.3절
|
||||
- [ ] IME 조합 중에 검증하거나 제출하지 않는다. — DS 8.1절
|
||||
|
||||
시각
|
||||
|
||||
@@ -58,7 +58,7 @@ paths:
|
||||
|
||||
폼
|
||||
|
||||
- [ ] label·설명·오류가 연결되고, 제출 실패 시 오류 요약으로 포커스가 가며, 요약 항목은 그 필드로 간다. — `docs/design/2026-07-26-design-system-platform-design.md` 8.3절
|
||||
- [ ] label·설명·오류가 연결되고, 입력 오류로 제출이 실패하면 첫 오류 필드로 포커스가 가며, 오류 요약 항목은 그 필드로 간다(`src/presentation/forms/use-app-form.ts` `focusFirstError`). — `docs/design/2026-07-26-design-system-platform-design.md` 8.3절
|
||||
- [ ] 409를 검증 오류로 위장하지 않는다. 이탈 확인(`useDirtyNavigationGuard`)은 성공 저장 뒤 풀고 이동한다. — `docs/design/2026-07-26-typescript-state-and-data-flow-design.md` 8절, `docs/design/2026-07-26-routing-pages-and-patterns-design.md` 6.4절
|
||||
- [ ] 자동 완성·IME·붙여넣기·비밀번호 관리자를 막지 않는다. 입력을 loading skeleton으로 덮지 않는다. — data-flow 8절
|
||||
|
||||
|
||||
@@ -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}
|
||||
>
|
||||
|
||||
@@ -12,6 +12,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 +25,20 @@ 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).
|
||||
function closeOnEscape(event: KeyboardEvent) {
|
||||
if (event.key === "Escape") {
|
||||
if (event.key === "Escape" && !event.defaultPrevented) {
|
||||
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 +47,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 +55,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 />
|
||||
|
||||
@@ -7,29 +7,47 @@ 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 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 leaves
|
||||
// the Escape alone.
|
||||
function dismissOnEscape(event: KeyboardEvent) {
|
||||
if (event.key === "Escape") setDismissed(true);
|
||||
if (event.key !== "Escape" || event.defaultPrevented) 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)}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { render, screen, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { useState } from "react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
Dialog,
|
||||
Menu,
|
||||
Popover,
|
||||
SearchField,
|
||||
TextArea,
|
||||
ToastProvider,
|
||||
Tooltip,
|
||||
useToast,
|
||||
} from "../../src/presentation/design-system/index.ts";
|
||||
|
||||
/**
|
||||
* 1112/05-10, 05-11, 05-13, 05-14, 05-17. What the shared primitives promise
|
||||
* a keyboard and screen reader user (docs/design/2026-07-26-design-system-platform-design.md
|
||||
* 8.1·8.2절, WCAG 2.2 AA): a named dialog, Escape that closes the innermost
|
||||
* layer only, required shown both ways, focus that does not fall to the body,
|
||||
* and a counter that is not announced on every key.
|
||||
*/
|
||||
|
||||
function DialogWith({ onClose, children }: Readonly<{ onClose(): void; children: React.ReactNode }>) {
|
||||
return (
|
||||
<Dialog open onClose={onClose} title="설정">
|
||||
{children}
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
describe("Popover", () => {
|
||||
it("names its dialog after the trigger", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<Popover triggerLabel="설명 열기">
|
||||
<Button>내부 작업</Button>
|
||||
</Popover>,
|
||||
);
|
||||
|
||||
await user.click(screen.getByRole("button", { name: "설명 열기" }));
|
||||
|
||||
expect(screen.getByRole("dialog", { name: "설명 열기" })).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Escape inside a Dialog", () => {
|
||||
it("closes an open Popover and keeps the Dialog", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onClose = vi.fn();
|
||||
render(
|
||||
<DialogWith onClose={onClose}>
|
||||
<Popover triggerLabel="설명 열기">
|
||||
<Button>내부 작업</Button>
|
||||
</Popover>
|
||||
</DialogWith>,
|
||||
);
|
||||
await user.click(screen.getByRole("button", { name: "설명 열기" }));
|
||||
await user.click(screen.getByRole("button", { name: "내부 작업" }));
|
||||
|
||||
await user.keyboard("{Escape}");
|
||||
|
||||
expect(screen.queryByRole("button", { name: "내부 작업" })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "설명 열기" })).toHaveFocus();
|
||||
expect(onClose).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("closes an open Menu and keeps the Dialog", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onClose = vi.fn();
|
||||
render(
|
||||
<DialogWith onClose={onClose}>
|
||||
<Menu triggerLabel="더 보기" items={[{ id: "copy", label: "복사", onSelect: () => {} }]} />
|
||||
</DialogWith>,
|
||||
);
|
||||
await user.click(screen.getByRole("button", { name: "더 보기" }));
|
||||
expect(screen.getByRole("menu")).toBeVisible();
|
||||
|
||||
await user.keyboard("{Escape}");
|
||||
|
||||
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
||||
expect(onClose).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("hides a shown Tooltip and keeps the Dialog", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onClose = vi.fn();
|
||||
render(
|
||||
<DialogWith onClose={onClose}>
|
||||
<Tooltip content="자세한 설명">
|
||||
<Button>도움말</Button>
|
||||
</Tooltip>
|
||||
</DialogWith>,
|
||||
);
|
||||
await user.hover(screen.getByRole("button", { name: "도움말" }));
|
||||
|
||||
await user.keyboard("{Escape}");
|
||||
|
||||
expect(screen.getByRole("tooltip", { hidden: true })).not.toBeVisible();
|
||||
expect(onClose).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("closes the Dialog when no inner layer is open", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onClose = vi.fn();
|
||||
render(
|
||||
<DialogWith onClose={onClose}>
|
||||
<Button>안쪽 버튼</Button>
|
||||
</DialogWith>,
|
||||
);
|
||||
screen.getByRole("button", { name: "안쪽 버튼" }).focus();
|
||||
|
||||
await user.keyboard("{Escape}");
|
||||
|
||||
expect(onClose).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("required fields", () => {
|
||||
it("marks a required SearchField both on the input and with the symbol", () => {
|
||||
render(<SearchField label="검색" required value="" onChange={() => {}} clearLabel="지우기" onClear={() => {}} />);
|
||||
|
||||
expect(screen.getByRole("searchbox", { name: /검색/u })).toBeRequired();
|
||||
expect(screen.getByText("*", { exact: false })).toHaveAttribute("aria-hidden", "true");
|
||||
});
|
||||
|
||||
it("marks a required Checkbox both on the input and with the symbol", () => {
|
||||
render(<Checkbox label="약관에 동의" required />);
|
||||
|
||||
const checkbox = screen.getByRole("checkbox", { name: /약관에 동의/u });
|
||||
expect(checkbox).toBeRequired();
|
||||
const label = checkbox.closest("label");
|
||||
if (!label) throw new Error("expected the checkbox label");
|
||||
expect(within(label).getByText("*", { exact: false })).toHaveAttribute("aria-hidden", "true");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Toast focus when it is closed", () => {
|
||||
function Harness({ count }: Readonly<{ count: number }>) {
|
||||
const toast = useToast();
|
||||
return (
|
||||
<Button
|
||||
onClick={() => {
|
||||
for (let index = 0; index < count; index += 1) {
|
||||
toast.push({ id: `toast-${index}`, title: `알림 ${index}`, durationMs: 60_000 });
|
||||
}
|
||||
}}
|
||||
>
|
||||
알림 보이기
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
it("moves focus to the next toast's close button", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<ToastProvider>
|
||||
<Harness count={2} />
|
||||
</ToastProvider>,
|
||||
);
|
||||
await user.click(screen.getByRole("button", { name: "알림 보이기" }));
|
||||
const [first] = screen.getAllByRole("button", { name: /닫기/u });
|
||||
if (!first) throw new Error("expected two close buttons");
|
||||
first.focus();
|
||||
|
||||
await user.click(first);
|
||||
|
||||
expect(document.activeElement).not.toBe(document.body);
|
||||
expect(document.activeElement).toBe(screen.getByRole("button", { name: /닫기/u }));
|
||||
});
|
||||
|
||||
it("returns focus to where it was before the last toast took it", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<ToastProvider>
|
||||
<Harness count={1} />
|
||||
</ToastProvider>,
|
||||
);
|
||||
const trigger = screen.getByRole("button", { name: "알림 보이기" });
|
||||
await user.click(trigger);
|
||||
await user.tab();
|
||||
const close = screen.getByRole("button", { name: /닫기/u });
|
||||
expect(close).toHaveFocus();
|
||||
|
||||
await user.keyboard("{Enter}");
|
||||
|
||||
expect(screen.queryByRole("article")).not.toBeInTheDocument();
|
||||
expect(trigger).toHaveFocus();
|
||||
});
|
||||
});
|
||||
|
||||
describe("TextArea counter", () => {
|
||||
it("describes the field without announcing every key", async () => {
|
||||
const user = userEvent.setup();
|
||||
function Controlled() {
|
||||
const [value, setValue] = useState("");
|
||||
return <TextArea label="메모" maxLength={30} value={value} onChange={(event) => setValue(event.currentTarget.value)} />;
|
||||
}
|
||||
render(<Controlled />);
|
||||
const field = screen.getByRole("textbox", { name: "메모" });
|
||||
|
||||
await user.type(field, "가나다");
|
||||
|
||||
expect(screen.queryByRole("status")).not.toBeInTheDocument();
|
||||
expect(field).toHaveAccessibleDescription(/27/u);
|
||||
});
|
||||
});
|
||||
@@ -5,7 +5,7 @@ import userEvent from "@testing-library/user-event";
|
||||
import { MemoryRouter } from "react-router-dom";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { LocaleProvider } from "../../src/presentation/i18n/index.ts";
|
||||
import { formatMessage, LocaleProvider } from "../../src/presentation/i18n/index.ts";
|
||||
import HomePage from "../../src/presentation/pages/home-page.tsx";
|
||||
import { ApplicationProvider } from "../../src/presentation/providers/application-provider.tsx";
|
||||
import { PreferenceProviders } from "../../src/presentation/providers/preference-providers.tsx";
|
||||
@@ -35,6 +35,16 @@ function renderApp(
|
||||
}
|
||||
|
||||
describe("starter home page", () => {
|
||||
// 1112/05-15. A generic div's aria-label is dropped by assistive technology;
|
||||
// the readiness list is a named group.
|
||||
it("names the readiness list as a group", async () => {
|
||||
renderApp("/");
|
||||
|
||||
expect(
|
||||
await screen.findByRole("group", { name: formatMessage("ko-KR", "home.readiness") }),
|
||||
).toBeVisible();
|
||||
});
|
||||
|
||||
it("reaches the platform overview from the starter actions", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderApp("/");
|
||||
|
||||
@@ -24,6 +24,30 @@ test("navigates to a registry-backed example without a page reload", async ({
|
||||
).toBeFocused();
|
||||
});
|
||||
|
||||
// 1112/05-02. The route heading takes focus on every navigation. A keyboard
|
||||
// user must see it (M2); a pointer user may not need the ring.
|
||||
test("shows the focus ring on the route heading after keyboard navigation only", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto("/");
|
||||
const link = page
|
||||
.getByRole("navigation", { name: "주요 탐색" })
|
||||
.getByRole("link", { name: "플랫폼 구성" });
|
||||
await link.focus();
|
||||
await page.keyboard.press("Enter");
|
||||
const heading = page.getByRole("heading", { level: 1, name: "플랫폼 구성" });
|
||||
await expect(heading).toBeFocused();
|
||||
expect(await heading.evaluate((element) => getComputedStyle(element).outlineStyle)).not.toBe("none");
|
||||
|
||||
await page
|
||||
.getByRole("navigation", { name: "주요 탐색" })
|
||||
.getByRole("link", { name: "홈" })
|
||||
.click();
|
||||
const home = page.getByRole("heading", { level: 1 });
|
||||
await expect(home).toBeFocused();
|
||||
expect(await home.evaluate((element) => getComputedStyle(element).outlineStyle)).toBe("none");
|
||||
});
|
||||
|
||||
test("provides an escape-dismissible mobile navigation", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await page.goto("/");
|
||||
|
||||
@@ -22,6 +22,22 @@ async function openDesignSystemGallery(page: Page) {
|
||||
).toBeVisible();
|
||||
}
|
||||
|
||||
// 1112/05-06. WCAG 1.4.13 hoverable: the pointer can move from the trigger
|
||||
// onto the tooltip, across the gap between them, and the tooltip stays.
|
||||
test("keeps a tooltip shown while the pointer moves onto it", async ({ page }) => {
|
||||
await openDesignSystemGallery(page);
|
||||
await page.getByRole("button", { name: "도움말" }).hover();
|
||||
const tooltip = page.getByRole("tooltip", { name: "이 설명은 필수 정보가 아닙니다." });
|
||||
await expect.poll(() => tooltip.evaluate((element) => getComputedStyle(element).opacity)).toBe("1");
|
||||
const box = await tooltip.boundingBox();
|
||||
if (!box) throw new Error("expected the tooltip box");
|
||||
|
||||
await page.mouse.move(box.x + box.width / 2, box.y + box.height + 2, { steps: 4 });
|
||||
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2, { steps: 4 });
|
||||
|
||||
await expect.poll(() => tooltip.evaluate((element) => getComputedStyle(element).opacity)).toBe("1");
|
||||
});
|
||||
|
||||
test("validates and reports the common text-field flow", async ({ page }) => {
|
||||
await openDesignSystemGallery(page);
|
||||
await page.getByRole("button", { name: "입력 확인" }).click();
|
||||
|
||||
Reference in New Issue
Block a user