Skip to content

feat(ui): add ghost copy button for single-line code blocks (#9085) - #9297

Open
hrithiksaini99 wants to merge 1 commit into
nodejs:mainfrom
hrithiksaini99:feat-one-line-codebox-ghost-copy-button
Open

hrithiksaini99 wants to merge 1 commit into
nodejs:mainfrom
hrithiksaini99:feat-one-line-codebox-ghost-copy-button

Conversation

@hrithiksaini99

Copy link
Copy Markdown

Description

Single-line code blocks (marked with no-footer by rehype-shiki) do not display the bottom toolbar to conserve vertical UI space, which left them without a quick copy action.

This PR adds a ghost copy button for single-line code blocks that:

  • Sits in the top-right corner of the code block and becomes visible on hover or focus (opacity-0 by default, opacity-100 on :hover / :focus-within).
  • Adds appropriate right padding (pr-24) to single-line code blocks so overflowing text is never occluded.
  • Adds comprehensive unit tests for BaseCodeBox covering default footer rendering, ghost copy button rendering on no-footer, and clipboard copy interactions.

Validation

  • Ran pnpm --filter @node-core/ui-components test: 46 passing tests (including new unit tests for BaseCodeBox).
  • Ran pnpm --filter @node-core/ui-components lint: 0 errors.
  • Ran pnpm --filter @node-core/ui-components build: Clean build.
  • Pre-commit hooks passed.

Related Issues

Fixes #9085

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run pnpm format to ensure the code follows the style guide.
  • I have run pnpm test to check if all tests are passing.
  • I have run pnpm build to check if the website builds without errors.
  • I've covered new added functionality with unit tests if necessary.

@hrithiksaini99
hrithiksaini99 requested a review from a team as a code owner November 2, 2026 19:50
@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nodejs-org Ready Ready Preview Nov 2, 2026 7:52pm UTC

Request Review

Comment on lines +112 to +113
<ButtonIcon className="size-4" />
{copied ? copiedButtonLabel : copyButtonLabel}

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.

IMO you should use 2 icon to mark as copied and you shouldn't use text


import BaseCodeBox from '../index';

navigator.clipboard = { writeText: () => Promise.resolve() };

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.

note: globals should NOT be mocked outside of a test environment. This here will propagate to all unit tests. Please change that :)

<ButtonIcon className="size-4" />
{copied ? copiedButtonLabel : copyButtonLabel}
</BaseButton>
) : !language ? null : (

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.

Can you make separate {} checks, instead of chaining these?

}
}

& > .ghostAction {

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.

Please add screenshots on how it looks on the PR description for dark/light theme 🙇

This branch was successfully deployed

1 active deployment
Preview — dc4f15df Deployed Nov 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI: one line code block ghost copy button

3 participants