Repository navigation
Description
Context
Part of #2576.
(Disclosure, packages/ui-kit/src/blocks/Disclosure.tsx:63-160) draws its summary as <div role="button" tabIndex={0} aria-expanded> with a hand-written Enter/Space handler (:96-100, :115-123), and mounts its children only while open (:145-157). It has 14 call sites: 11 in ui-react plus TurnErrorCard, PlaceMap and ModelPicker in ui-kit (grep -rn "<Disclosure" packages/*/src).
D27 (components-and-interactions.md, "D27: Disclosure becomes optionally controlled") binds three modes: uncontrolled (neither prop), seeded (open alone, read once), and controlled (open + onOpenChange). onOpenChange fires on every toggle in all modes. The controlled mode's guarantee is that a parent that ignores the callback gets a disclosure that does not open.
<details>/<summary> gives the role, the keys and the state natively, and its content is reachable by find-in-page: Chromium auto-expands a closed <details> on a match. Guide html/html: "DO use <details> and <summary> for native accordions or revealable content without JS." Guide ui-behaviors/search-hidden-content covers the find-in-page reveal.
Scope
- Render
<details>with a<summary>that carries today's summary row (icon, label, badge, meta, chevron). Hide the native marker (list-style: none,::-webkit-details-marker), and keepbk-controland the hover/focus paint. - Keep D27's three modes:
- Uncontrolled and seeded mirror the native
toggleevent (event.currentTarget.open) into state and callonOpenChange. - Controlled renders the
openattribute from the prop. It callspreventDefault()on the summary click (and on keyboard activation, if the browser routes it separately) and callsonOpenChange(!open), so a parent that ignores the callback keeps it closed. - A
togglethe component did not ask for (find-in-page) callsonOpenChange(true). In controlled mode the prop value is then re-applied.
- Uncontrolled and seeded mirror the native
- Keep children lazy: mount them on the first open and keep them mounted after that, so find-in-page can reach text the user has already seen. A never-opened disclosure stays empty, as it is today.
- No animation. Opening and closing stay instant, as today.
Out of scope
- Exclusive accordions via
<details name>. D27's accordion is parent-controlled and stays that way. - Animating
::details-contentwithinterpolate-size. That is new motion, which needs a design ruling. File it separately if wanted. - Changing
DisclosureProps. - Any change to call sites beyond test selectors.
Acceptance criteria
- The rendered summary is a native
<summary>inside<details>, with norole="button",tabIndexor key handler. - The existing D27 stories (
OpenPropIsSeedOnly,Controlled,Accordion) pass unchanged. InControlled, a parent that ignoresonOpenChangestill gets a disclosure that does not open after a click, Enter or Space. - Browser-initiated expansion works for a disclosure that has been opened once and then closed. Chromium auto-expands
<details>on fragment navigation the same way it does for find-in-page, so the test navigates to a fragment id inside the content.onOpenChange(true)fires, and in controlled mode the rendered state ends up matching the prop. - Summary paint, the 44px reach (D34) and the focus ring match the current baselines in both themes.
- A browser test that asserts native
<summary>semantics fails on the current tree. A mutation that removes the controlledpreventDefault()makes theControlledstory fail. Record both in the PR. - Changeset for
@schlessera/brain-ui-kit(patch).
Verification
node scripts/visual.mjs --project=storybook --project=storybook-light --filter=Disclosure.stories
node scripts/visual.mjs --project=visual
bun run test packages/ui-kit packages/ui-react
bun run typecheck
bun run lintContract impact
- This touches the integration contract, so it needs the
contractlabel, aCONTRACT:commit prefix, and the doc updated in the same commit. - This changes a published package's behaviour, so it needs a changeset.
DisclosureProps and the three-mode semantics in package-api.md ("Disclosure coverage badge") are unchanged. Only the rendered element changes.
Activity