Skip to content

Fix ToggleSwitch knob spacing and border-radius to match primer/react - #4107

Merged
dylanatsmith merged 6 commits into
mainfrom
dats/fix-toggleswitch-knob-styling
Jun 23, 2026
Merged

Fix ToggleSwitch knob spacing and border-radius to match primer/react#4107
dylanatsmith merged 6 commits into
mainfrom
dats/fix-toggleswitch-knob-styling

Conversation

@dylanatsmith

@dylanatsmith dylanatsmith commented Jun 23, 2026

Copy link
Copy Markdown
Member

What

The ToggleSwitch knob (the part that slides back and forth) didn't match the styling in primer/react. This PR aligns the knob's spacing, border-radius, and shadow with react's ToggleKnob.

ToggleSwitch.mp4

Changes

In app/components/primer/alpha/toggle_switch.pcss, the .ToggleSwitch-knob:

  • Spacing — was flush to the track (top: 0; bottom: 0); now inset 1px on all sides (top/bottom/left: 1px), so the knob sits within the track's border. The checked-state translate is updated to translateX(calc(100% - 2px)) to account for the inset.
  • Border-radius — changed from var(--borderRadius-medium) to calc(var(--borderRadius-medium) - var(--borderWidth-thick)), matching react so the knob's corners nest correctly inside the track border.
  • Box-shadow — removed (--shadow-resting-medium, --button-default-shadow-inset); react's ToggleKnob has no shadow. The now-redundant box-shadow: none in the disabled state was also dropped.

Source of truth: primer/react ToggleSwitch.module.css.ToggleKnob.

Notes

  • Visual regression / ARIA snapshots will need regenerating.

The knob now sits inset 1px from the track edges and uses a border-radius
that accounts for the track border, matching the ToggleKnob styles in
primer/react.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 625dfcf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/view-components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dylanatsmith
dylanatsmith force-pushed the dats/fix-toggleswitch-knob-styling branch from 1bb7ddf to f4cac1b Compare June 23, 2026 16:36
@dylanatsmith
dylanatsmith marked this pull request as ready for review June 23, 2026 16:48
@dylanatsmith
dylanatsmith requested a review from a team as a code owner June 23, 2026 16:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Aligns the ToggleSwitch knob styling in @primer/view-components with the primer/react ToggleSwitch knob, primarily to better match spacing within the track border and the knob’s corner treatment.

Changes:

  • Adjusts the checked-state knob translate and updates knob positioning to be inset from the track edges.
  • Updates knob border-radius calculation and removes knob shadow styling.
  • Adds a changeset for a patch release.
Show a summary per file
File Description
app/components/primer/alpha/toggle_switch.pcss Updates ToggleSwitch knob spacing/translate and border-radius to better match primer/react.
.changeset/toggle-switch-knob-styling.md Adds a patch changeset describing the visual alignment change.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 3

Comment thread app/components/primer/alpha/toggle_switch.pcss Outdated
Comment thread app/components/primer/alpha/toggle_switch.pcss Outdated
Comment thread app/components/primer/alpha/toggle_switch.pcss Outdated
…ties

Introduce --toggleSwitch-knob-inset (the track border width) and
--toggleSwitch-knob-offset (twice the inset), rooting the knob inset,
checked travel, and concentric border-radius in a single source of truth.
No visual change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Collapse top/bottom/left into a single inset declaration (right kept auto),
which also drops three needless primer/spacing stylelint-disable comments.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the four-value inset shorthand with inset-block and
inset-inline-start, dropping the auto filler for the inline-end edge.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dylanatsmith
dylanatsmith merged commit 222a846 into main Jun 23, 2026
32 checks passed
@dylanatsmith
dylanatsmith deleted the dats/fix-toggleswitch-knob-styling branch June 23, 2026 18:44
@primer primer Bot mentioned this pull request Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants