Skip to content

BranchName: Add leadingVisual, trailingAction and description#7993

Open
siddharthkp wants to merge 22 commits into
mainfrom
siddharthkp/branchname-trailing-action-component
Open

BranchName: Add leadingVisual, trailingAction and description#7993
siddharthkp wants to merge 22 commits into
mainfrom
siddharthkp/branchname-trailing-action-component

Conversation

@siddharthkp

@siddharthkp siddharthkp commented Jun 15, 2026

Copy link
Copy Markdown
Member

API proposal document for upstreaming patterns from production usage into the BranchName component:

  1. Leading visual — a branch/tag icon before the name
  2. Trailing action — copy button, branch switcher menu
  3. Description tooltip — shows owner/repo:branch context

The proposal recommends Option A — Compound component based on analysis of github-ui usage patterns.

Changelog

New

  • API proposal document at packages/react/src/BranchName/BranchName.api-proposal.md

Changed

None

Removed

None

Rollout strategy

  • None; this is a proposal document only, no code changes

Testing & Reviewing

Review the proposal document for API design feedback.

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews (Storybook)
  • Changes are SSR compatible
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge
  • (GitHub staff only) Integration tests pass at github/github-ui

siddharthkp and others added 5 commits June 10, 2026 11:55
Demonstrate a trailing action pattern (copy button) for BranchName,
serving as a reference for future implementation work.

Add WithTrailingActionMenu story with SelectPanel

Demonstrates branch switching via SelectPanel anchored to BranchName,
showing the 'Change base branch' pattern.

Remove overflow:hidden to prevent focus ring clipping
@changeset-bot

This comment was marked as resolved.

@github-actions github-actions Bot 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 Jun 15, 2026
@github-actions

This comment was marked as resolved.

@primer

primer Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

🤖 Lint issues have been automatically fixed and committed to this PR.

@github-actions github-actions Bot temporarily deployed to storybook-preview-7993 June 15, 2026 14:41 Inactive
@siddharthkp siddharthkp changed the title BranchName API proposal Upstream BranchName features Jun 16, 2026
- Add BranchName.LeadingVisual for branch/tag icons
- Add BranchName.TrailingAction for copy/menu buttons
- Add description prop for tooltip (aria-describedby)
- Update stories to use new compound API
- Add comprehensive tests for new API
…e-trailing-action-component

# Conflicts:
#	packages/react/src/BranchName/BranchName.features.stories.tsx
@siddharthkp siddharthkp changed the title Upstream BranchName features BranchName: Add leadingVisual, trailingAction and description Jun 16, 2026
@github-actions github-actions Bot requested a deployment to storybook-preview-7993 June 16, 2026 22:01 Abandoned
- Merge BranchName.new-api.test.tsx into BranchName.test.tsx
- Document description/className props and LeadingVisual/TrailingAction subcomponents
- Refresh story ids in docs.json
@primer

primer Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

🤖 Lint issues have been automatically fixed and committed to this PR.

@github-actions github-actions Bot requested a deployment to storybook-preview-7993 June 16, 2026 22:07 Abandoned
@primer

primer Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

🤖 Lint issues have been automatically fixed and committed to this PR.

@primer

primer Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

🤖 Lint issues have been automatically fixed and committed to this PR.

@github-actions github-actions Bot requested a deployment to storybook-preview-7993 June 17, 2026 09:37 Abandoned
…wrapping

LeadingVisual and TrailingAction now accept rest props and merge className. Collapse the description-tooltip branches into a single ConditionalTooltip render path.
@primer

primer Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

🤖 Formatting issues have been automatically fixed and committed to this PR.

@github-actions github-actions Bot temporarily deployed to storybook-preview-7993 June 18, 2026 11:51 Inactive
@github-actions github-actions Bot temporarily deployed to storybook-preview-7993 June 18, 2026 12:02 Inactive
@github-actions github-actions Bot requested a deployment to storybook-preview-7993 June 18, 2026 12:11 Abandoned
@github-actions github-actions Bot temporarily deployed to storybook-preview-7993 June 18, 2026 12:21 Inactive
@siddharthkp siddharthkp marked this pull request as ready for review June 22, 2026 10:37
@siddharthkp siddharthkp requested a review from a team as a code owner June 22, 2026 10:37
@siddharthkp siddharthkp requested review from Copilot and joshblack June 22, 2026 10:37
@siddharthkp siddharthkp requested review from francinelucca and llastflowers and removed request for joshblack June 22, 2026 10:38

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

This PR evolves BranchName (in packages/react) from a simple link/text pill into a compound component API that supports a leading visual, a trailing action button, and an optional description tooltip, with corresponding styling, Storybook examples, test coverage, VRT snapshots, and a release changeset.

Changes:

  • Add BranchName.LeadingVisual and BranchName.TrailingAction slot subcomponents plus a description tooltip prop in BranchName.
  • Update CSS to support icon alignment and a trailing-action container layout.
  • Update Storybook “Features” stories, unit/type tests, and e2e VRT coverage; add a changeset.
Show a summary per file
File Description
packages/react/src/BranchName/BranchName.tsx Implements compound slot API (LeadingVisual, TrailingAction) and conditional description tooltip rendering.
packages/react/src/BranchName/BranchName.module.css Switches to flex layout; adds styling for leading visual spacing and trailing-action wrapper/divider.
packages/react/src/BranchName/BranchName.features.stories.tsx Updates stories to demonstrate the new compound API, description tooltip, and menu anchoring via anchorRef.
packages/react/src/BranchName/BranchName.docs.json Documents the new description prop and subcomponents; expands referenced Storybook story IDs.
packages/react/src/BranchName/tests/BranchName.types.test.tsx Updates type-level assertions to reflect the new as constraints and ref/event typing.
packages/react/src/BranchName/tests/BranchName.test.tsx Adds unit tests for leading visual, trailing action behavior, and tooltip/aria-describedby behavior.
e2e/components/BranchName.test.ts Expands VRT story coverage (including focus snapshots) for the new variants.
.changeset/whole-rings-glow.md Adds a release note entry for the updated BranchName API.

Copilot's findings

  • Files reviewed: 8/71 changed files
  • Comments generated: 6

Comment on lines +67 to +79
const {as: Component = 'a', className, children, description, ...rest} = props as BranchNameProps<'a'>

const [slots, textChildren] = useSlots(children, {
leadingVisual: LeadingVisual,
trailingAction: TrailingAction,
})

const link = (
<ConditionalTooltip description={description}>
<Component
{...rest}
ref={ref as React.Ref<HTMLAnchorElement>}
className={clsx(className, classes.BranchName)}
Comment on lines +43 to 50
export type BranchNameProps<As extends 'span' | 'a'> = PolymorphicProps<
As,
'a',
{
className?: string
/** Description tooltip text (renders as aria-describedby) */
description?: string
}

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.

Wondering about this, I found a few instances of other elements in dotcom

Comment on lines 29 to 33
"name": "ref",
"type": "React.RefObject<HTMLAnchorElement>"
},
{
"name": "as",
Comment on lines +70 to +76
{
"name": "className",
"type": "string",
"required": false,
"description": "A custom class name that is merged with the leading visual's class. Additional `span` props are forwarded to the underlying element.",
"defaultValue": ""
}
"@primer/react": minor
---

BranchName: Add `leadingVisual`, `trailingAction` and `description` prop
Comment on lines +1 to +5
---
"@primer/react": minor
---

BranchName: Add `leadingVisual`, `trailingAction` and `description` prop

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

few comments/questions. Also noticed a mild css diff in the actionmenu story in the active state, not sure which one's correct:

Screen.Recording.2026-06-22.at.10.32.12.AM.mov

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.

noticed some of these are displaying tooltips and some aren't, just want to make sure this doesn't become flaky vrt 👀

Comment on lines +43 to 50
export type BranchNameProps<As extends 'span' | 'a'> = PolymorphicProps<
As,
'a',
{
className?: string
/** Description tooltip text (renders as aria-describedby) */
description?: string
}

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.

Wondering about this, I found a few instances of other elements in dotcom


// With a trailing action, render the action as a sibling of the link
return (
<span className={classes.BranchNameWithTrailingAction} data-component="BranchName.WrapperWithAction">

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.

we don't do wrappers so this data-component is probably not needed

Comment on lines -23 to -26
<Stack direction="horizontal" gap="condensed" align="center">
<Octicon icon={GitBranchIcon} />
branch_name
</Stack>

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.

is the previous way still supported? just making sure this isn't a breaking change

Comment on lines -107 to -108
<span className={styles.BranchNameWithTrailingAction}>
<BranchName href={`https://github.com/${repo}/tree/${selected.text}`} className={styles.BranchNameTransparent}>

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.

any dead css as a result of this we can cleanup?

Comment on lines +17 to +18
// Note: the story was renamed to "With Leading Visual" but we keep the
// snapshot title as "With A Branch Icon" so the VRT diff stays usable.

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.

curious how this works 👀

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.

double-checking that the change in spacing here is expected

@primer-integration

Copy link
Copy Markdown

Integration test results from github/github-ui PR:

Failed  CI   Failed
Passed  VRT   Passed
Passed  Projects   Passed

CI check runs linting, type checking, and unit tests. Check the workflow logs for specific failures.

Need help? If you believe this failure is unrelated to your changes, please reach out to the Primer team for assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants