#065
Controlled
A single-open Accordion with its open item bound to state and the current value printed below.
Hand this to your AI. It names the exact library parts, timings and accessibility promises of this demo.
Build the "Controlled" pattern (@codeatlasdev/ui demo #065, surfaces/accordion) in my app.
Call get_demo({ ids: ["#065"] }) first and keep its structure. It needs @codeatlasdev/[email protected].
Use: FAQ or settings sections where the app needs to read or set which item is open.
Keep these library parts, with the props and tokens the demo uses:
- Accordion, AccordionItem from "@codeatlasdev/ui"
Behaviour to keep:
- `<Accordion type="single" bind:value>`
- State: `let value = $state<string | string[] | undefined>('c1')` opens the first item initially
- 2 items: `<AccordionItem value="c1" title="First section">` and `<AccordionItem value="c2" title="Second section">`
- `Open item: {Array.isArray(value) ? value.join(', ') : (value ?? 'none')}` prints the bound value
- Wrapped in `.wrap` with `max-width: 560px`
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
- Accordion
@codeatlasdev/ui - AccordionItem
@codeatlasdev/ui
How it is built
- `<Accordion type="single" bind:value>`
- State: `let value = $state<string | string[] | undefined>('c1')` opens the first item initially
- 2 items: `<AccordionItem value="c1" title="First section">` and `<AccordionItem value="c2" title="Second section">`
- `Open item: {Array.isArray(value) ? value.join(', ') : (value ?? 'none')}` prints the bound value
- Wrapped in `.wrap` with `max-width: 560px`
Related
Loading source.