diff --git a/.claude/skills/fe-a11y/SKILL.md b/.claude/skills/fe-a11y/SKILL.md index d3b2def6..5d764f24 100644 --- a/.claude/skills/fe-a11y/SKILL.md +++ b/.claude/skills/fe-a11y/SKILL.md @@ -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절 시각 diff --git a/.claude/skills/fe-ux/SKILL.md b/.claude/skills/fe-ux/SKILL.md index 3cb18f56..afa7fc08 100644 --- a/.claude/skills/fe-ux/SKILL.md +++ b/.claude/skills/fe-ux/SKILL.md @@ -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절 diff --git a/src/presentation/design-system/primitives/checkbox.tsx b/src/presentation/design-system/primitives/checkbox.tsx index bfce9843..b132724b 100644 --- a/src/presentation/design-system/primitives/checkbox.tsx +++ b/src/presentation/design-system/primitives/checkbox.tsx @@ -42,7 +42,11 @@ export const Checkbox = forwardRef( }} type="checkbox" /> - {label} + + {label} + {/* 1112/05-13. The symbol as Field draws it; the state is on the input. */} + {props.required ? : null} + {description ? (

diff --git a/src/presentation/design-system/primitives/dialog.tsx b/src/presentation/design-system/primitives/dialog.tsx index fcb0ea3b..8e1563d2 100644 --- a/src/presentation/design-system/primitives/dialog.tsx +++ b/src/presentation/design-system/primitives/dialog.tsx @@ -41,6 +41,7 @@ export const Dialog = forwardRef( const dialogRef = useRef(null); const previousFocusRef = useRef(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( 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} > diff --git a/src/presentation/design-system/primitives/escape-layer.ts b/src/presentation/design-system/primitives/escape-layer.ts new file mode 100644 index 00000000..ada44548 --- /dev/null +++ b/src/presentation/design-system/primitives/escape-layer.ts @@ -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); +} diff --git a/src/presentation/design-system/primitives/popover.tsx b/src/presentation/design-system/primitives/popover.tsx index 98e1438d..6b9e8490 100644 --- a/src/presentation/design-system/primitives/popover.tsx +++ b/src/presentation/design-system/primitives/popover.tsx @@ -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(null); const triggerRef = useRef(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) { {open ? ( -