Skip to content

Add experimental clipboard copying APIs - #8826

Draft
adierkens wants to merge 5 commits into
mainfrom
adierkens-upstream-copy-to-clipboard
Draft

adierkens wants to merge 5 commits into
mainfrom
adierkens-upstream-copy-to-clipboard

Conversation

@adierkens

@adierkens adierkens commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: e1693661b965583c3147eb44a2335361a0a7909d

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ Browser tests cover copy outcomes, stale overlapping writes, unmount, accessible description, keyboard use, and variant foreground colors (16/16).
↑ Primary and danger color tests fail without the CSS fix.
↑ Build, type-check, ESLint, Stylelint, Prettier, and 3/3 clipboard accessibility e2e tests passed locally.
↑ Latest Copilot review reports no open issues.
↑ All 40 CI checks passed on this revision.
↓ No visual regression baselines were added; new experimental APIs have no downstream usage yet.

Add reusable clipboard copying APIs with accessible success and failure feedback.

Changelog

New

  • Experimental CopyToClipboardButton, useCopyToClipboard, and copyText.
  • Confirm successful writes, report failures, and preserve the button's accessible name.

Changed

Removed

Rollout strategy

Opt-in experimental exports; no existing APIs change.

Testing & Reviewing

Copy with each variant: default and invisible show success or failure colors, while primary and danger keep their contrasting foreground.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@adierkens
adierkens requested a balanced review from Copilot November 23, 2026 21:55
@changeset-bot

changeset-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e169366

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

This PR includes changesets to release 1 package
Name Type
@primer/react Minor

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-actions github-actions Bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Nov 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions
github-actions Bot requested a deployment to storybook-preview-8826 November 23, 2026 22:01 Abandoned

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.

🟡 Changes recommended

Overlapping clipboard writes can announce stale results, and inherited description and keyboard shortcut props are silently ignored.

2 open issues
What changed in this PR

Adds experimental clipboard APIs to Primer React, offering a ready-made copy button, a reusable state hook, and a standalone text-copy utility.

Changes:

  • Adds clipboard writes with a legacy fallback and success/error state tracking.
  • Introduces CopyToClipboardButton with feedback tooltips, announcements, and a stable accessible name.
  • Adds tests, Storybook examples, documentation, experimental exports, and a minor changeset.
File Description
packages/​react/​src/​utils/​copyText.ts Implements clipboard writes and selection-based fallback.
packages/​react/​src/​utils/​copyText.test.ts Tests writes, failures, and fallback cleanup.
packages/​react/​src/​hooks/​useCopyToClipboard.ts Tracks copy state, errors, and feedback timing.
packages/​react/​src/​hooks/​useCopyToClipboard.test.tsx Tests timing, retries, overlapping requests, and unmounting.
packages/​react/​src/​hooks/​useCopyToClipboard.hookDocs.json Documents hook options and results.
packages/​react/​src/​experimental/​index.ts Exports the new experimental APIs and types.
packages/​react/​src/​CopyToClipboardButton/​index.ts Exports the component and props.
packages/​react/​src/​CopyToClipboardButton/​CopyToClipboardButton.tsx Composes the copy button and outcome feedback.
packages/​react/​src/​CopyToClipboardButton/​CopyToClipboardButton.test.tsx Tests feedback, naming, keyboard use, and disabled behavior.
packages/​react/​src/​CopyToClipboardButton/​CopyToClipboardButton.stories.tsx Adds component and custom-control examples.
packages/​react/​src/​CopyToClipboardButton/​CopyToClipboardButton.module.css Styles success and error states.
packages/​react/​src/​CopyToClipboardButton/​CopyToClipboardButton.docs.json Adds component metadata and prop documentation.
packages/​react/​src/​__tests__/​ssr.test.tsx Adds server-rendering coverage for the button.
packages/​react/​src/​__tests__/​__snapshots__/​exports.test.ts.snap Records the new experimental exports.
e2e/​components/​CopyToClipboardButton.test.ts Adds accessibility checks for feedback and disabled states.
contributor-docs/​copy-to-clipboard.md Explains usage, feedback responsibilities, and browser constraints.
.changeset/​copy-to-clipboard.md Records a minor release for the new APIs.

Review effort: Balanced

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

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.

🔵 Needs a closer look

The outcome colors override the primary button’s contrasting foreground, leaving the success checkmark at only 1.12:1 contrast against its green background and making confirmation difficult to see.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve contrasting foreground for primary outcome buttons

packages/​react/​src/​CopyToClipboardButton/​CopyToClipboardButton.module.css:1

The outcome colors also override the foreground for variant="primary", while ButtonBase keeps its green primary background. For example, the success checkmark becomes #1a7f37 on #1f883d in the light theme—only 1.12:1 contrast—making the confirmation difficult to see. Preserve the primary variant's contrasting foreground instead of applying these semantic foreground colors to it.

2 resolved since last review

Review effort: Balanced

Limit success and failure colors to the default and invisible variants so
primary and danger buttons keep their contrasting foregrounds.

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

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.

🟢 Approval recommended

No active review issues were identified for the opt-in experimental clipboard APIs.

No open issues 🎉

Review effort: Balanced

This branch was successfully deployed

2 active deployments
storybook-preview-8826 — e1693661 Deployed Nov 24, 2026 by github-actions[bot]
github-pages — e1693661 Deployed Nov 24, 2026 by adierkens via deploy-preview #34517
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants