feat(react): add the AlertDialog primitive#20
Open
ivanbanov wants to merge 2 commits into
Open
Conversation
Adds @dunky.dev/alert-dialog (framework-free state machine) and @dunky.dev/react-alert-dialog (React binding). Anatomy: root, Trigger, Portal, Backdrop, Viewport, Content, Title, Description, Cancel, Action. A modal confirmation dialog per the APG alertdialog pattern: always modal, outside presses never dismiss, Escape closes (vetoable), initial focus lands on Cancel, and controlled open only moves with the prop. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the AlertDialog primitive as two packages:
@dunky.dev/alert-dialog— the framework-free state machine (core), built on@dunky.dev/state-machine.@dunky.dev/react-alert-dialog— the thin React binding.An alert dialog is a modal window that interrupts the user with an urgent question and requires a response, per the WAI-ARIA APG alertdialog pattern. Where a plain dialog can be waved away, an alert dialog cannot: it is always modal, an outside press never dismisses it, and the only ways out are the Cancel/Action parts and Escape.
Anatomy
Behavior
role="alertdialog"+aria-modal="true", focus is trapped inside, background scroll is locked, and outside presses never dismiss.onEscapeKeyDown(event.preventDefault()); backdrop/viewport presses are not a dismissal.openis truly controlled: every open/close intent (trigger press, Escape, Cancel/Action) is reported throughonOpenChange, but the alert dialog only moves when the prop does — ignoring a report is a working veto (e.g. hold it open while an async destructive operation resolves). Prop-driven transitions are not echoed back.aria-labelledby/aria-describedbyfollow the rendered Title/Description — an omitted part never leaves a dangling reference.data-state="open|closed"on the stateful parts is the styling hook; no positioning engine — the Viewport is the consumer's layout layer.Test plan
pnpm test:ci— 145 tests, 13 files, all passingpnpm typecheckpnpm lintpnpm format:checkpnpm build🤖 Generated with Claude Code