Skip to content

refactor(ui,settings): Round D — SettingsSegmented primitive + retire 4 hand-rolled radiogroup helpers - #268

Merged
jackwener merged 1 commit into
mainfrom
yuejing/settings-segmented-primitive
Jun 25, 2026
Merged

refactor(ui,settings): Round D — SettingsSegmented primitive + retire 4 hand-rolled radiogroup helpers#268
jackwener merged 1 commit into
mainfrom
yuejing/settings-segmented-primitive

Conversation

@jackwener

Copy link
Copy Markdown
Member

Summary

@WAWQAQ msg `f1461d30` 「用库的应该用库」: continue collapsing the hand-rolled wrappers in SettingsModal.tsx into shared @maka/ui primitives.

Primitive

packages/ui/src/primitives/settings-segmented.tsx wraps Base UI's ToggleGroup (single-select by default). Caller's className (legacy .settingsSegmented) still owns the visual chrome — the primitive only contributes Base UI's behavior contract.

Migration

  • function Segmented deleted from SettingsModal. 3 call sites use the imported primitive aliased as Segmented so their JSX is byte-identical.
  • .settingsSegmented button[data-active=\"true\"][data-pressed] (Base UI's Toggle state attribute).

Helper retirement

With Theme/Palette migrated via #263 (ChoiceCard) and Segmented migrated here, all four hand-rolled keyboard-nav helpers in SettingsModal are dead:

  • onSettingsRadioGroupKeyDown, focusRadioValue, radioTabIndex — deleted.
  • nextRadioId import — deleted from SettingsModal.

nextRadioId itself stays in model-table-keyboard.ts because ProvidersPanel's model default picker keeps its hand-rolled radiogroup.

Contract test pivot

Keyboard-nav assertion in settings-theme-contract.test.ts flips: was 'Segmented uses the legacy helpers' → 'Segmented imports SettingsSegmented; the local function Segmented declaration is gone; the 4 hand-rolled helpers are gone'.

Test plan

  • pnpm -F @maka/ui build — clean.
  • tsc --noEmit -p apps/desktop/tsconfig.renderer.json — only the pre-existing unrelated TS2366.
  • settings-theme-contract.test.ts — 6/6 pass.
  • renderer-style-pruning-contract.test.ts — 2/2 pass.
  • Visual smoke: Settings → 模型 / 通用 pages with Segmented pills still toggle correctly; arrow keys cycle between options; active pill has the white background + light shadow chrome.

… 4 hand-rolled radiogroup helpers

@WAWQAQ msg `f1461d30` 「用库的应该用库」: continue collapsing the
hand-rolled wrappers in SettingsModal.tsx into shared `@maka/ui`
primitives.

**New primitive.** `packages/ui/src/primitives/settings-segmented.tsx`
wraps Base UI's `ToggleGroup` (single-select by default). Caller's
`className` (legacy `.settingsSegmented`) still owns the visual chrome
— the primitive only contributes Base UI's behavior contract.

**Migration.** SettingsModal's `function Segmented` is gone (3 call
sites use the imported primitive aliased as `Segmented` so their
markup is byte-identical). `.settingsSegmented button[data-active=
"true"]` → `[data-pressed]` to match Base UI's Toggle state attribute.

**Helper retirement.** With Theme/Palette migrated via #263
(`ChoiceCard`) and Segmented migrated here, the four hand-rolled
keyboard-nav helpers in SettingsModal — `onSettingsRadioGroupKeyDown`,
`focusRadioValue`, `radioTabIndex`, and the `nextRadioId` import —
are all dead. Removed. `nextRadioId` itself stays in
`model-table-keyboard.ts` because ProvidersPanel's model default
picker keeps its hand-rolled radiogroup; that's a separate lane.

**Contract test pivot.** The keyboard-nav assertion in
`settings-theme-contract.test.ts` flips from "Segmented uses the
legacy helpers" → "Segmented imports SettingsSegmented from
@maka/ui; the local function Segmented declaration is gone; the 4
hand-rolled helpers are gone". Same regression-prevention intent,
pinned one layer up.

All test suites pass:
  ✔ Settings theme page contract  (6/6)
  ✔ renderer style pruning contract  (2/2)
@jackwener
jackwener merged commit 01b18c9 into main Jun 25, 2026
@jackwener
jackwener deleted the yuejing/settings-segmented-primitive branch June 25, 2026 19:05
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.

1 participant