Skip to content

fix(ui): forward ToggleGroup's orientation to the primitive - #166

Merged
KenTaniguchi-R merged 1 commit into
mainfrom
fix/toggle-group-orientation
Sep 7, 2026
Merged

fix(ui): forward ToggleGroup's orientation to the primitive#166
KenTaniguchi-R merged 1 commit into
mainfrom
fix/toggle-group-orientation

Conversation

@KenTaniguchi-R

Copy link
Copy Markdown
Owner

A bug in #165, found by finally running the keyboard check that PR shipped without.

What is wrong

ToggleGroup takes orientation as its own prop, destructures it, and spends it on data-orientation and the class list. It never reaches ToggleGroupPrimitive. Base UI's composite drives arrow-key movement from the real prop, so it kept its horizontal default.

The vertical date-preset group added in #165 is the first caller to notice. It renders as a column but moves with Left/Right, and Up/Down does nothing:

ArrowDown  → focus did not move
ArrowRight → focus moved

The four pre-existing callers (appearance-toggle, date-range-selector, account-list, holdings-table) are all horizontal, which is why this survived until a vertical group existed.

Fix is one line: pass orientation to the primitive as well as the data attribute.

How this got in

#165 shipped the keyboard behaviour unverified, and I said so in its description — CI cannot see it, since there were no component tests. I also said I could not verify it without Chrome remote debugging. That was wrong: Base UI's roving focus is plain JS and jsdom drives it fine. Five green checks and a reviewed mock did not catch a control navigating along the wrong axis.

The regression test

src/components/ui/toggle-group.test.tsx pins all four directions — vertical moves on ArrowDown and not on ArrowRight, horizontal moves on ArrowRight, and the group is a single tab stop.

Getting it to run at all needed vitest to accept .tsx:

  • include now covers src/**/*.test.tsx.
  • A component test declares @vitest-environment jsdom in its own docblock, so the node default still applies to every other file.

No projects, no workspace, no CI change. This also closes the "component tests are not currently possible" gap recorded in AGENTS.md — worth a follow-up to reword that line once this lands.

Not the same bug

size on Card, Avatar, Select, Switch and AlertDialog, and align on InputGroup, follow the same destructure-to-data-attribute shape. Those are styling-only props shadcn expresses that way deliberately. orientation is the one that changes what the primitive does, which is what made it a bug. Checked, no other instances.

Testing

pnpm typecheck, pnpm lint, and the new test under the project's real vitest config all pass (4/4).

Still not verified in a browser. The test drives Base UI's focus management directly, which is where the bug was, but a pass through the Reports date picker would confirm it end to end.

🤖 Generated with Claude Code

Base UI's composite drives arrow-key movement from `orientation`, but our
wrapper destructured the prop and spent it on `data-orientation` and the
class list only, so the primitive never saw it and kept its horizontal
default. The vertical date-preset group added in #165 was the first caller
to notice: visually a column, but Left/Right moved through it and Up/Down
did nothing.

    ArrowDown  → focus did not move
    ArrowRight → focus moved

The four pre-existing callers are horizontal, which is why this survived
until a vertical group existed.

Comes with a regression test, which needs vitest to accept `.tsx` at all:
`include` now covers `src/**/*.test.tsx`, and a component test declares
`@vitest-environment jsdom` in its own docblock so the node default still
applies to everything else. No projects, no CI change.

Worth stating why the sibling wrappers are not the same bug: `size` on
Card, Avatar, Select, Switch and AlertDialog, and `align` on InputGroup,
are styling-only props shadcn expresses as data attributes on purpose.
`orientation` is the one that changes what the primitive does.
@KenTaniguchi-R
KenTaniguchi-R merged commit 183a50d into main Sep 7, 2026
5 checks passed
@KenTaniguchi-R
KenTaniguchi-R deleted the fix/toggle-group-orientation branch September 7, 2026 11:40
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