Skip to content

Add count to SegmentedControlButton - #6721

Merged
langermank merged 13 commits into
mainfrom
seg-cont-count
Sep 15, 2025
Merged

Add count to SegmentedControlButton#6721
langermank merged 13 commits into
mainfrom
seg-cont-count

Conversation

@cheshire137

@cheshire137cheshire137 commented Sep 4, 2025

Copy link
Copy Markdown
Member

This adds a new count prop to SegmentedControl.Button, modeled after the counter that UnderlineNav.Item has and the count that Button has.

screenshot of Storybook showing With Counter Labels story for SegmentedControl

cc @francinelucca with whom I talked about adding such a prop

Changelog

New

Adds the count prop to SegmentedControl.Button to allow displaying a count label on the right side of the button.

Changed

Removed

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

The SegmentedControl > Features > With Counter Labels story and SegmentedControl > SegmentedControl.Button > Playground story have been updated to show off the new prop.

Merge checklist

Modeled after the counter in packages/react/src/UnderlineNav/UnderlineNavItem.tsx and how it's rendered in packages/react/src/internal/components/UnderlineTabbedInterface.tsx.
@cheshire137cheshire137 self-assigned this Sep 4, 2025
CopilotAI review requested due to automatic review settings September 4, 2025 14:08
@cheshire137
cheshire137 requested a review from a team as a code ownerSeptember 4, 2025 14:08
@changeset-bot

changeset-botBot commented Sep 4, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 175a276

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

This PR includes changesets to release 2 packages
NameType
@primer/reactMinor
@primer/styled-reactMajor

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

@github-actionsgithub-actionsBot added staff Author is a staff member integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Sep 4, 2025
@github-actions

Copy link
Copy Markdown
Contributor

👋 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!

@github-actions

github-actionsBot commented Sep 4, 2025

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
packages/react/dist/browser.esm.js89.42 KB (-0.23% 🔽)
packages/react/dist/browser.umd.js89.63 KB (+0.08% 🔺)

@github-actions
github-actionsBot requested a deployment to storybook-preview-6721 September 4, 2025 14:16 Abandoned
@primer-integration

Copy link
Copy Markdown

👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/1723

CopilotAI 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

This PR adds a new counter prop to SegmentedControl.Button to display count labels on the right side of buttons, following the same pattern as UnderlineNav.Item. This feature enables displaying numeric counts alongside segment labels, useful for scenarios like showing issue counts by label type.

  • Adds counter prop accepting number or string values to SegmentedControlButton
  • Implements counter rendering using the existing CounterLabel component with proper spacing
  • Updates Storybook stories and documentation to showcase the new functionality

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
FileDescription
SegmentedControlButton.tsxAdds counter prop type definition and conditional rendering logic
SegmentedControlButton.stories.tsxUpdates Playground story to include counter control
SegmentedControl.module.cssAdds CSS styling for counter positioning and alignment
SegmentedControl.features.stories.tsxAdds new "With Counter Labels" feature story
SegmentedControl.docs.jsonDocuments the new counter prop in component metadata

@joshblackjoshblack 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 so much for taking the time to submit a PR! Appreciate it a ton 🙏

Just left a couple of comments/suggestions, hope they make sense. I also tagged in @langermank on the design side to review 🔍

Comment thread.changeset/unlucky-hotels-shake.md Outdated
"description": "Whether the segment is selected. This is used for uncontrolled SegmentedControls to pick one SegmentedControlButton that is selected on the initial render."
},
{
"name": "counter",

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.

Random question for you @langermank, do you know why for Button we call this count. but for UnderlineNav.Item it's counter? 🤔

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.

I don't think there's any logical reason other than they were probably added at different times and by different people, and it would be nice if they matched 😄

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.

@langermank do you have a preference for count or counter? Mine would be count, I think

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.

Agree on "count"!

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I can update!

Comment threadpackages/react/src/SegmentedControl/SegmentedControl.module.css Outdated
cheshire137and others added 3 commits September 4, 2025 13:57
https: //github.com//pull/6721#discussion_r2322729732
Co-Authored-By: Josh Black <3901764+joshblack@users.noreply.github.com>
https: //github.com//pull/6721#discussion_r2322722420
Co-Authored-By: Josh Black <3901764+joshblack@users.noreply.github.com>

@langermanklangermank 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.

Some squishyness happening, I haven't taken a closer look to find a solution but happy to if needed!

Squishy

@cheshire137 if you wouldn't mind, could you add the new feature story you added to this file so it will create a VRT snapshot? No worries if not, we can add it in a followup!

"description": "Whether the segment is selected. This is used for uncontrolled SegmentedControls to pick one SegmentedControlButton that is selected on the initial render."
},
{
"name": "counter",

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.

I don't think there's any logical reason other than they were probably added at different times and by different people, and it would be nice if they matched 😄

@github-actions
github-actionsBottemporarily deployed to storybook-preview-6721 September 8, 2025 14:04 Inactive
@joshblackjoshblack added the update snapshots 🤖 Command that updates VRT snapshots on the pull request label Sep 8, 2025
@primer
primerBot requested a review from a team as a code ownerSeptember 8, 2025 16:53
@github-actionsgithub-actionsBot removed the update snapshots 🤖 Command that updates VRT snapshots on the pull request label Sep 8, 2025
cheshire137and others added 2 commits September 9, 2025 10:25
https: //github.com//pull/6721/files#r2330801548
Co-Authored-By: Katie Langerman <18661030+langermank@users.noreply.github.com>
Co-Authored-By: Josh Black <3901764+joshblack@users.noreply.github.com>
@cheshire137cheshire137 changed the title Add counter to SegmentedControlButtonAdd count to SegmentedControlButtonSep 9, 2025
@github-actions
github-actionsBottemporarily deployed to storybook-preview-6721 September 9, 2025 15:38 Inactive

@langermanklangermank 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.

I'm going to open a followup PR to fix the overflow problem 👍

@cheshire137

Copy link
Copy Markdown
MemberAuthor

Oh heck, I forgot all about that comment, sorry about that and thank you @langermank! If you'd prefer, we could get it fixed in this branch.

@langermank

Copy link
Copy Markdown
Contributor

@cheshire137 no worries at all. I dug into it and its not really tied to the count addition, it's pre-existing. So I think it's probably better to fix it in a separate PR anyway!

@cheshire137

Copy link
Copy Markdown
MemberAuthor

I'll get conflicts resolved.

@langermank
langermank added this pull request to the merge queueSep 15, 2025
@github-actions
github-actionsBottemporarily deployed to storybook-preview-6721 September 15, 2025 16:22 Inactive
Merged via the queue into main with commit d6378c2Sep 15, 2025
42 of 43 checks passed
@langermank
langermank deleted the seg-cont-count branch September 15, 2025 16:26
@primerprimerBot mentioned this pull request Sep 15, 2025
pksjce pushed a commit that referenced this pull request Sep 18, 2025
Co-authored-by: Josh Black <3901764+joshblack@users.noreply.github.com>
Co-authored-by: Josh Black <joshblack@github.com>
Co-authored-by: Katie Langerman <18661030+langermank@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommendedThis change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpmstaffAuthor is a staff member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@cheshire137@langermank@joshblack