#462
Type to confirm
A destructive alert dialog with a rich description and a TextField body; Confirm stays disabled until the key is typed.
Hand this to your AI. It names the exact library parts, timings and accessibility promises of this demo.
Build the "Type to confirm" pattern (@codeatlasdev/ui demo #462, feedback/alert-dialog) in my app.
Call get_demo({ ids: ["#462"] }) first and keep its structure. It needs @codeatlasdev/[email protected].
Use: Irreversible deletes that need a deliberate confirmation, such as typing the item key.
Keep these library parts, with the props and tokens the demo uses:
- AlertDialog, Button, TextField from "@codeatlasdev/ui"
Behaviour to keep:
- Trigger `<Button variant="destructive"` labelled `Delete {key}` with a `<Trash2 size={14} />` leading icon; it resets `typed = ''` and opens the dialog
- `<AlertDialog` with `bind:open`, `title="Delete {key}?"`, `confirmLabel="Delete"`, `cancelVariant="outlined"` and `destructive`
- `confirmDisabled={typed !== key}` where `const key = 'PRJ-42'`, and `confirmProps={{ 'data-testid': 'confirm-delete' }}`
- `{#snippet description()}` renders `This removes <strong>3 linked records</strong> too and cannot be undone.`
- Body is `<TextField label="Type {key} to confirm" bind:value={typed} />`
- `onconfirm` sets `deleted = true`, which shows `{key} deleted.` in a `<span class="out" aria-live="polite">`
Reduced motion: the demo handles it; keep that branch.
Keyboard: operable; keep the focus order and key handling.
Change only the copy and the data. Use the theme tokens (--ca-*), never raw colours. Library parts
- AlertDialog
@codeatlasdev/ui - Button
@codeatlasdev/ui - TextField
@codeatlasdev/ui
How it is built
- Trigger `<Button variant="destructive"` labelled `Delete {key}` with a `<Trash2 size={14} />` leading icon; it resets `typed = ''` and opens the dialog
- `<AlertDialog` with `bind:open`, `title="Delete {key}?"`, `confirmLabel="Delete"`, `cancelVariant="outlined"` and `destructive`
- `confirmDisabled={typed !== key}` where `const key = 'PRJ-42'`, and `confirmProps={{ 'data-testid': 'confirm-delete' }}`
- `{#snippet description()}` renders `This removes <strong>3 linked records</strong> too and cannot be undone.`
- Body is `<TextField label="Type {key} to confirm" bind:value={typed} />`
- `onconfirm` sets `deleted = true`, which shows `{key} deleted.` in a `<span class="out" aria-live="polite">`
Related
Loading source.