Skip to content

refactor(studio): use the Toggle primitive in the chat composer area - #2362

Merged
peppescg merged 2 commits into
mainfrom
refactor/studio-composer-primitives
Oct 16, 2026
Merged

peppescg merged 2 commits into
mainfrom
refactor/studio-composer-primitives

Conversation

@peppescg

Copy link
Copy Markdown
Contributor

Summary

Group A of #2201 covers the chat composer area: chat-composer.tsx, composer-options-sheet.tsx, model-effort-menu.tsx and side-thread-panel.tsx under apps/web/src/features/chat/. The six hand-rolled aria-pressed controls in these files now use the Toggle primitive. The #2340 and #2337 call sites in chat-composer.tsx were reviewed. All of them are kept, for the reasons in the decision table.

Names, roles, pressed state, keyboard use and pixels are unchanged in every captured state. Computed colours are also unchanged in every captured state: rest, hover and keyboard focus, in light and dark.

Closes #2336
Part of #2340
Part of #2337
Part of #2201
Part of #2210

The Execution picker's native <select> (on hold, #2326/#2335), Canvas and every title= attribute are untouched. Draft #2099 also edits chat-composer.tsx and model-effort-menu.tsx, in different areas.

What changed

Decision table

Line numbers are on main (550c67fee). For #2340, #2352 listed the same three sites at L720, L725 and L950 on its own base.

Call site (apps/web/src/features/chat/) Issue Pattern Decision
chat-composer.tsx:793 #2336 Dictation button, aria-pressed Changed → Toggle. A single independent on/off control.
side-thread-panel.tsx:368 #2336 Thread dictation button, aria-pressed Changed → Toggle. A single independent on/off control.
composer-options-sheet.tsx:221 #2336 Effort pills, aria-pressed Changed → one Toggle per pill. Not ToggleGroup type="single": Radix renders that as a radiogroup of radios with roving focus. That would replace aria-pressed with aria-checked, collapse the six Tab stops into one, and add arrow-key movement inside a sheet that closes on each pick. This follows #2334's roster rows.
composer-options-sheet.tsx:297 #2336 Mode rows, aria-pressed Changed → one Toggle per row. Same reason as the Effort pills.
model-effort-menu.tsx:291 #2336 Default model row, aria-pressed Changed → Toggle. It belongs to the model list below.
model-effort-menu.tsx:315 #2336 Model rows, aria-pressed Changed → one Toggle per row. Same reason as the Effort pills. The rows also sit under provider headings and behind a search field, which a single roving group would cut across.
chat-composer.tsx:735 #2340 role="alert", attachment error Kept. It is an inline field error: one line of text under the message field, with no frame and no action. Alert would add a framed banner inside the composer. This matches the inline errors #2352 kept.
chat-composer.tsx:740 #2340 role="alert", dictation error Kept. Same as above: an inline error about the field's dictation input.
chat-composer.tsx:965 #2340 Native <label> Kept. It wraps the Execution picker's native <select>, which is on hold (#2326/#2335). The picker may be redesigned or removed, so its label moves with it.
(these four files) #2340 aria-expanded disclosures None found, so no Collapsible or Accordion is needed. (components/ui/collapsible.tsx only exists in the still-open #2352.)
chat-composer.tsx:655 #2337 animate-pulse Kept. It is the dot beside "Listening", a status pulse that shows dictation is active. It is not a loading placeholder, so Skeleton doesn't apply. This matches the status dots #2358 kept.

After this PR, no hand-rolled aria-pressed remains in the four files. delegation-panel.tsx and content-preview-panel.tsx are covered by #2334.

Behaviour differences

  • Radix attributes. Radix adds data-state="on|off" to each Toggle, and data-disabled when it is disabled. Everything else stays the same: element (button, type="button"), role, name, aria-pressed, Tab order, and Enter and Space handling.
  • Hover on disabled controls. A disabled Mode row, Model row or Effort pill no longer shows its hover fill under a mouse. The Toggle base sets disabled:pointer-events-none. Before, a native disabled button still matched :hover and showed a faded hover fill. The dictation buttons already had this through Button.
  • Pressing the current choice. It still picks that choice again and closes the sheet. onPressedChange runs on every press, whatever the new pressed value.
  • Effort pill layout properties. The pills report different computed justify-content, align-items and gap (inline-flex instead of a native button's centring). Their transition-property is none instead of all with a duration of 0. Both render the same pixels.

No regression

  • Pins first (ef4574648): composer-toggles.pinning.test.tsx (16 tests). They pass on main's code and unchanged on the head. They cover:

    • Composer dictation: name, aria-pressed and "Listening" by click, Enter and Space. Focus is kept, and the button is disabled while busy.
    • Mode rows: only the current mode is pressed. A pick closes the sheet and the new mode shows pressed on reopen. Pressing the current mode again picks it again. Enter and Space work.
    • Model rows: only the chosen model is pressed, Default included. A model or Default can be picked, the chosen one again, and with Space.
    • Effort pills: labels and order, only the current one pressed, a pick and a repeat pick close the sheet, and Enter works.
    • Side thread dictation: click, Enter and Space. The button is absent where the browser cannot dictate.
    • Every choice: a plain button with no role or aria-checked, and its own Tab stop.

    No existing test was modified. The existing aria-pressed assertion in chat-composer.alignment.test.tsx passes unchanged.

  • Mutation proof. Each mutation was applied alone and the pins rerun:

    Mutation Failing pins
    Composer dictation without onPressedChange 2
    Composer dictation pressed inverted 3
    Thread dictation without onPressedChange 1
    Thread dictation pressed inverted 1
    Effort pill acts only when turning on 1 (pick again)
    Mode row acts only when turning on 1 (pick again)
    Mode row not bound to the current value 2
    Model row acts only when turning on 1 (pick again)
    Default row not bound to the selection 1
    Effort pills in a single-choice ToggleGroup 3 (roles, Tab stops, pick)
  • Pixels. Each tree was captured twice. Before = After in every shot and state, within the noise seen between two captures of the same tree (at most 34 px, outside the controls).

  • Computed styles. The two trees were also probed in Chromium for every converted control, pressed and unpressed, at rest, under the mouse and with keyboard focus, in light and dark. The phone sheet was probed at 390px with a mouse so hover applies. Colours, borders, radii, sizes, padding, font, outline and ring match. The only differences are the layout properties listed under Behaviour differences.

    Two mismatches were found and fixed this way before the head commit: the 16px vs 20px phone glyph, and the chosen model row's light-mode hover fill.

Screenshots

Before (550c67fee, main) | After (03b14d115) | Prototype (stack-08). Amber boxes mark the converted controls. A red box would mark a Before/After pixel difference; there are none. The sheet views are phone-only (min-[500px]:hidden), so they have no desktop shots.

Composer, dictation on (pressed), desktop light (zoomed). The prototype has the same tinted pressed mic. Its label reads "Stop listening" where Studio's reads "Stop dictation", which this PR doesn't change.

Phone sheet, Model view with GPT-5 and High chosen, light. The rows and pills match the prototype's structure. The prototype's star buttons and model list come from its own fixtures.

Composer: dictation off and on, desktop and 390px, light and dark

composer-off-desktop-light

composer-on-desktop-light

composer-off-mobile-light

composer-on-mobile-light

composer-off-desktop-dark

composer-on-desktop-dark

composer-off-mobile-dark

composer-on-mobile-dark

composer-off-desktop-light-zoom

composer-on-desktop-light-zoom

composer-off-desktop-dark-zoom

composer-on-desktop-dark-zoom

Phone sheet: Mode view (Manual chosen) and Model view, light and dark

sheet-mode-mobile-light

sheet-mode-mobile-dark

sheet-model-mobile-light

sheet-model-mobile-dark

Side thread: dictation off and on, desktop and 390px, light and dark (the prototype column is its unpressed thread composer)

thread-off-desktop-light

thread-on-desktop-light

thread-off-mobile-light

thread-on-mobile-light

thread-off-desktop-dark

thread-on-desktop-dark

thread-off-mobile-dark

thread-on-mobile-dark

thread-off-desktop-light-zoom

thread-on-desktop-light-zoom

thread-off-desktop-dark-zoom

thread-on-desktop-dark-zoom

In the side thread shots, the thread body reads "Loading thread..." in both trees because of the offline fixture. Only the composer row is under test there.

Gates

Both run on the head through the shared gate lock.

  • task studio:check: passes.
    • Web Vitest: 1602 tests in 182 files. Base: 1586 in 181, plus the 16 pins.
    • Server: 252 tests in 27 files, unchanged.
  • task studio:browser: passes, 136 passed and 38 skipped, unchanged from base (no browser journey was added or changed).

🤖 Generated with Claude Code

peppescg and others added 2 commits October 15, 2026 17:06
Pins the composer's and the side thread's dictation buttons and the phone
sheet's Mode rows, Model rows and Effort pills before they move to the
Toggle primitive: names, aria-pressed, click, Enter and Space, picking the
current choice again, and one Tab stop per choice.

Refs #2336

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…essed controls

The composer's and the side thread's dictation buttons, and the phone
sheet's Mode rows, Model rows and Effort pills, become Toggles. Each
choice stays its own Toggle rather than a single-choice ToggleGroup, which
would turn them into radios with roving focus. Class overrides keep the
previous look; names, pressed state and keyboard use are unchanged.

Closes #2336

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@kantord kantord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, and for documenting why these are separate Toggles rather than a single-choice ToggleGroup (that would have changed roles and Tab order). I traced the class merging and the handlers: onPressedChange={voice.toggle} is safe because toggle takes no arguments, and pressing the already-pressed pill or row still re-selects it. Approving, with a few non-blocking nits:

  • The rows and pills need long override strings (toggleRowClass, effortPillClass, the model rows) to undo the Toggle's defaults, and the dictation class is duplicated between the composer and the side thread. #2334 solved the same smell with a ghost variant, so a variant (or a shared constant for the dictation class) may be worth a follow-up.
  • Each mic icon gets size-4 by hand because a Toggle isn't a Button, so the phone glyph rule doesn't cover it. That is the same class of problem #2368 fixes for Buttons, one primitive over.
  • In model-effort-menu.tsx, the comment says hovering the chosen row keeps the zinc fill in dark "as before". As far as I can tell, dark:data-[state=on]:hover:bg-zinc-800 is new and the dark pressed-hover fill changes from muted/50 to zinc-800. I'm only moderately sure of the specificity, so please double-check the comment and the screenshot.

Fully or partially written by an AI agent.

@peppescg
peppescg merged commit 9f08f63 into main Oct 16, 2026
31 checks passed
@peppescg
peppescg deleted the refactor/studio-composer-primitives branch October 16, 2026 08:56
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 20, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Studio: replace the remaining hand-rolled toggles with the Toggle primitive

2 participants