#146
autofocus
An input that receives focus on mount, with a button that remounts it through a keyed block.
Hand this to your AI. It names the exact library parts, timings and accessibility promises of this demo.
Build the "autofocus" pattern (@codeatlasdev/ui demo #146, navigation/actions) in my app.
Call get_demo({ ids: ["#146"] }) first and keep its structure. It needs @codeatlasdev/[email protected].
Use: Dialogs, inline editors and search fields where the first field should take focus as soon as it appears.
Keep these library parts, with the props and tokens the demo uses:
- Button from "@codeatlasdev/ui"
- autofocus from "@codeatlasdev/ui/actions"
Behaviour to keep:
- `use:autofocus` imported from `@codeatlasdev/ui/actions` on a native `<input`
- Input has `placeholder="Focused on mount"` and `aria-label="Autofocused input"`
- `let key = $state(0)` drives `{#key key}` around the input
- `<Button onclick={() => key++}>Remount input</Button>` remounts the input so focus is applied again
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
- Button
@codeatlasdev/ui
How it is built
- `use:autofocus` imported from `@codeatlasdev/ui/actions` on a native `<input`
- Input has `placeholder="Focused on mount"` and `aria-label="Autofocused input"`
- `let key = $state(0)` drives `{#key key}` around the input
- `<Button onclick={() => key++}>Remount input</Button>` remounts the input so focus is applied again
Related
Loading source.