Skip to content

ui-kit: Disclosure hand-rolls a toggle button instead of rendering details/summary #2584

Open

Description

@schlessera

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 keep bk-control and the hover/focus paint.
  • Keep D27's three modes:
    • Uncontrolled and seeded mirror the native toggle event (event.currentTarget.open) into state and call onOpenChange.
    • Controlled renders the open attribute from the prop. It calls preventDefault() on the summary click (and on keyboard activation, if the browser routes it separately) and calls onOpenChange(!open), so a parent that ignores the callback keeps it closed.
    • A toggle the component did not ask for (find-in-page) calls onOpenChange(true). In controlled mode the prop value is then re-applied.
  • 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-content with interpolate-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 no role="button", tabIndex or key handler.
  • The existing D27 stories (OpenPropIsSeedOnly, Controlled, Accordion) pass unchanged. In Controlled, a parent that ignores onOpenChange still 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 controlled preventDefault() makes the Controlled story 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 lint

Contract impact

  • This touches the integration contract, so it needs the contract label, a CONTRACT: 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

  1. added
    type: refactor
    area: ui-kit
    priority: p3
    agent-ready
    on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyarea: ui-kitpriority: p3type: refactor

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions