Remove use of useResponsiveValue hook - SegmentedControl#7134
Conversation
🦋 Changeset detectedLatest commit: 9fb549c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks! |
c36b54a to
7aa11ea
Compare
7aa11ea to
0f1a1ef
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the SegmentedControl component to use CSS-based responsive behavior via getResponsiveAttributes instead of the runtime useResponsiveValue hook. This change moves responsive logic from JavaScript to CSS, enabling more efficient rendering.
Key Changes:
- Replaced
useResponsiveValuehook withgetResponsiveAttributesutility forfullWidthandvariantprops - Removed JavaScript logic that transformed Buttons to IconButtons for hideLabels variant; now handled via CSS by hiding
.Textelements - Always renders both dropdown and segmented control variants when dropdown is used at any breakpoint, with CSS controlling visibility
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| SegmentedControl.tsx | Replaced useResponsiveValue with getResponsiveAttributes; removed hideLabels transformation logic; refactored rendering to always output both dropdown and segmented control when dropdown variant is present |
| SegmentedControl.module.css | Added comprehensive responsive styles for full-width and variant behaviors across all breakpoints; added CSS variable for icon width; added DropdownContainer styles |
| SegmentedControl.responsive.stories.tsx | Added new story file demonstrating responsive fullWidth, hideLabels, and dropdown variants across breakpoints |
| .changeset/segmentedcontrol-responsive.md | Added changeset documenting the change |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
🟢 ci completed with status |
|
👋 Hi, there are new commits since the last successful integration test. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Or, apply the |
|
👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/7334 |
Closes https://github.com/github/primer/issues/6027
This implementation should fix all flickering caused by hydration mismatches.
Changelog
Unfortunately, there isn't a great way to reduce this repetition in standard CSS while maintaining the media query scoping. The pattern requires:
This structure can't easily be compressed because:
The current code is actually following the established pattern in the codebase (like in Hidden.module.css).
While repetitive, it's explicit and maintainable, and colocated.
New
Stories
segmentedcontrol-responsive-tests--complex-responsive
Screen.Recording.2025-11-07.at.15.34.56.mov
segmentedcontrol-responsive-tests--full-width-responsive
Screen.Recording.2025-11-07.at.15.35.24.mov
segmentedcontrol-responsive-tests--variant-dropdown-responsive
Screen.Recording.2025-11-07.at.15.35.46.mov
segmentedcontrol-responsive-tests--variant-hide-labels-responsive
Screen.Recording.2025-11-07.at.15.36.16.mov
Changed
SegmentedControl.module.cssto support responsivefullWidthandvariantprops using data attributes, enabling different layouts (e.g., full width, dropdown, hide labels) at narrow, regular, and wide breakpoints.SegmentedControl.tsxto conditionally render dropdown and segmented button variants based on responsive props, and removed the previous use ofuseResponsiveValue.Rollout strategy
Testing & Reviewing
Merge checklist