nodejs.org icon indicating copy to clipboard operation
nodejs.org copied to clipboard

Replace Toast notifications with inline feedback for "Code Copied" action

Open ShubhamOulkar opened this issue 3 months ago • 3 comments

Description

Problem Currently, when a user clicks the "Copy" button on a code block, the website triggers a global toast notification at the bottom of the screen to indicate success.

While visually common, this pattern introduces significant accessibility and usability issues. Recent discussions (referenced below) highlight that toast notifications are often problematic because:

  1. Timing: They often disappear too quickly for some users to read.
  2. Focus/Screen Readers: Assistive technology often misses them if focus isn't managed perfectly, leaving the user unsure if the action succeeded.
  3. Cognitive Load: They appear far away from the user's current locus of attention (the code block), making them easy to overlook.

Reference: Primer Design System: Toast Accessibility

Proposed Solution

We should remove the Toast dependency for the "Copy" action and instead implement inline feedback.

When the user clicks the copy button:

  • The feedback should appear inside the code block header, directly adjacent to or replacing the button itself.
  • Example: The copy icon could briefly change to a "Checkmark" icon, or the text "Copy" could change to "Copied!".
  • Benefit: This keeps the feedback within the user's current field of vision and is more logically associated with the trigger action.

Ref Slack message

ShubhamOulkar avatar Nov 20 '25 03:11 ShubhamOulkar

Example: The copy icon could briefly change to a "Checkmark" icon, or the text "Copy" could change to "Copied!".

To be honest, this would make the bundle a bit smaller, I imagine, since we no longer need to pass a Toast provider.

avivkeller avatar Nov 21 '25 01:11 avivkeller

We need one state, activity component and useEffectEvent timer to toggle states. 🤔 WDYT?

ShubhamOulkar avatar Nov 21 '25 01:11 ShubhamOulkar

Example: The copy icon could briefly change to a "Checkmark" icon, or the text "Copy" could change to "Copied!".

i could have this wrong but i thought changing the text like this was less accessible. The radix toast uses aria-live features

bmuenzenmeyer avatar Nov 21 '25 15:11 bmuenzenmeyer

Has there been any progress here?

ovflowd avatar Dec 25 '25 17:12 ovflowd

I feel that for the code boxes we can simply replace the text of "Copy to clipboard" to "Copied to clipboard!" and then change it back after a timeout.

ovflowd avatar Dec 25 '25 17:12 ovflowd

I'm working on this!

cnaples79 avatar Dec 25 '25 19:12 cnaples79