#721
Required choice with error
ChipGroup inside a native form with a required choice and a field error shown after submitting without a selection.
Hand this to your AI. It names the exact library parts, timings and accessibility promises of this demo.
Build the "Required choice with error" pattern (@codeatlasdev/ui demo #721, inputs/chip-group) in my app.
Call get_demo({ ids: ["#721"] }) first and keep its structure. It needs @codeatlasdev/[email protected].
Use: A form step with one required single choice, where the error must be announced and the value must reach FormData through `name`.
Keep these library parts, with the props and tokens the demo uses:
- Button, ChipGroup from "@codeatlasdev/ui"
Behaviour to keep:
- `<ChipGroup` with `label="Sales team size"`, `name="teamSize"`, `items={sizes}`, `bind:value={size}`, `{error}` and `required`
- `sizes` has 3 items: `1`, `2-5`, `6-20`
- `let size = $state('')` starts with nothing selected
- `onsubmit` prevents default and sets the error to `'Choose a team size.'` when `size` is empty
- `onchange` clears the error
- `<Button type="submit" variant="filled">Continue</Button>` submits the form
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
How it is built
- `<ChipGroup` with `label="Sales team size"`, `name="teamSize"`, `items={sizes}`, `bind:value={size}`, `{error}` and `required`
- `sizes` has 3 items: `1`, `2-5`, `6-20`
- `let size = $state('')` starts with nothing selected
- `onsubmit` prevents default and sets the error to `'Choose a team size.'` when `size` is empty
- `onchange` clears the error
- `<Button type="submit" variant="filled">Continue</Button>` submits the form
Related
Loading source.