hyderhusainarastu

Accessible Dialog Focus Trap Primitives — Development skill for Claude Code

Development community

Four small React hooks/components for accessible modals: focus trap, Escape to close, focus return to trigger and live-region announcements.

How to install Accessible Dialog Focus Trap Primitives

This entry records only its repository, not the path inside it, so there is no exact command to give. Open hyderhusainarastu/accessible-dialog-focus-trap-primitives and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

What Accessible Dialog Focus Trap Primitives does

Four small React hooks/components for accessible modals: focus trap, Escape to close, focus return to trigger and live-region announcements. Follows the WAI-ARIA dialog pattern. TypeScript, with tests, a worked example and a scaffold script.

Alternatives in Development

  • Scan Trap — 单独检查一只股票是不是杀猪盘 / 有没有被资金套路 6.6k ★
  • Pi Reserved Keybindings — Extensions cannot override these shortcuts — they are silently skipped by registerShortcut() 526 ★
  • Aria Hr — Use the @aria-hr agent to help the user with the following people/HR matter: $ARGUMENTS 523 ★

README

Accessible Dialog Focus-Trap Primitives

Four small, independently-testable React primitives that together make any modal, dialog, drawer, popover, or menu behave the way the [WAI-ARIA Dialog (Modal) Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/) requires: keyboard focus stays trapped inside while it's open, Escape closes it, focus returns to whatever opened it, and state changes that don't move focus still get announced to screen readers.

  • useFocusTrap — cycles Tab/Shift+Tab focus inside a container while it's active, wrapping at the edges instead of escaping to the page behind it.
  • useEscapeToClose — closes a surface on Escape, only while it's active, without stealing an Escape press meant for something else.
  • useFocusReturn — hands back a callback that restores focus to the control that opened the surface, once it closes.
  • LiveAnnouncer — a visually-hidden aria-live region for announcing state changes that have no visible focus target of their own.

Each primitive's trickiest logic is factored into a plain, DOM-free function (`resolveTabTarget`, `isEscapeDismissal`) so it's unit-testable with no jsdom, no Testing Library, and no browser at all — see `references/*.test.ts`.

Installation

Fastest path: copy the code into your project. Using it as an agent skill is optional.

1. Copy or scaffold the code (no agent needed)

node scripts/scaffold-dialog-primitives.mjs --out-dir ./src/components/dialog-primitives

Or copy `references/` and `examples/` by hand. Needs Node.js 18+ for the script, a React 18+ project (the code uses `useId`, `useCallback`, `useEffect`) and, if you keep the bundled tests, a Vitest-compatible runner (Jest's API is close, so they will likely run unmodified).

2. Install as an agent skill (optional)

Run `./install.sh` with no flags to see options and detected tools; nothing changes until you pick a target.

Surface How Status
Claude Code