Skip to content

ui-kit: balance short headings and wrap captions pretty #2601

Open

Description

@schlessera

Context

Kit headings wrap greedily. On a 320–390px phone, a two-line sheet or screen title often leaves one word alone on its second line. Only two kit elements set text-wrap today, and both use pretty:

  • the EmptyState body and note (textWrap, packages/ui-kit/src/conversation/EmptyState.tsx:178)
  • a MapView caption (textWrap, packages/ui-kit/src/blocks/MapView.tsx:1107)

The print renderer already uses balance on headings and pretty on paragraphs (packages/render-template/src/styles.ts:97, :120).

Guide visual-design/improve-text-layout-and-legibility: "For short text blocks like headings, use text-wrap: balance", and "Avoid elements that have visible boxes such as borders or backgrounds". The guide also notes that Chromium balances at most about 6 lines.

Support:

  • balance: Chrome Android 114, Samsung 23, Firefox Android 121.
  • pretty: Chrome Android 117, Samsung 24, not in Firefox.

Where a browser lacks either value, it falls back to ordinary wrapping, so no detection is needed.

Scope

text-wrap: balance on these title elements, none of which has its own border or background:

  • Overlay header h2: the .bk-overlay-header h2 rule (packages/ui-kit/src/tokens.css:2425)
  • BottomSheet title span (packages/ui-kit/src/chrome/BottomSheet.tsx:60-62)
  • ScreenHeader title (packages/ui-kit/src/chrome/ScreenHeader.tsx:93-100)
  • EmptyState title (titleRef, packages/ui-kit/src/conversation/EmptyState.tsx:164-171)
  • DigestCard title (packages/ui-kit/src/conversation/DigestCard.tsx:110-117)
  • HygieneCard headings (packages/ui-kit/src/decisions/HygieneCard.tsx:103, :206, :250)

text-wrap: pretty on these short captions:

  • BottomSheet subtitle (BottomSheet.tsx:70)
  • ScreenHeader description (ScreenHeader.tsx:140)

Out of scope

  • A global h1–h6 or p rule, and the ui-react markdown prose in theme.css.
  • ActionCard titles, which render through Ghosted loading text whose width must not jump between ghost and arrival.
  • Row titles (ListRow, ChoiceOption), chips and buttons.
  • The print renderer.

Acceptance criteria

  • Each element listed in Scope computes text-wrap-style: balance or pretty in a real browser, and no other kit element changes.
  • A Storybook play test fails before the change and passes after. It renders an Overlay and a BottomSheet at 320px with a title that wraps to two lines, and asserts that the two lines' widths differ by less than 30% of the wider one.
  • The re-recorded visual baselines contain only wrapping changes in the listed titles and captions. The PR shows before/after captures at 320px and 390px for review.
  • Android support: no detection is needed (see Context), and the PR records that Firefox keeps greedy wrapping for pretty.

Verification

node scripts/visual.mjs --project=storybook --filter=Overlay.stories
node scripts/visual.mjs --project=storybook --filter=BottomSheet.stories
bun run visual:update && git diff --stat
bun run visual
bun run test
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.

@schlessera/brain-ui-kit: visual-only patch.

Activity

  1. added
    type: feat
    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: feat

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions