Q391: Clipboard Feedback Drill Copy Buttons Toast States and Failure Handling
What Interviewers Want To Evaluate
This drill tests whether you can make a small utility feature feel reliable.
Copy buttons look simple, but the implementation touches browser permissions, async feedback, empty values, mobile behavior, accessibility, and user trust.
The interviewer wants to see whether you handle the edges instead of only calling navigator.clipboard.writeText.
Short Interview Answer
For copy actions, I would provide separate copy buttons for code and console output, use the Clipboard API when available, show clear copied or failed feedback, handle empty content, and keep the buttons keyboard accessible. I would also avoid copying hidden or stale output by deriving the copied text from the current editor and console state at the moment the user clicks.
Copy Targets
A practice ground may need:
copy code input
copy console output
copy current prompt
copy selected snippet later
copy error details later
Start with code and console.
Those are the highest-frequency actions.
Feedback States
Useful states:
idle
copying
copied
failed
empty
Do not leave the user guessing.
The button label or nearby status should change briefly after the action.
Clipboard API
Modern flow:
await navigator.clipboard.writeText(text);
But this can fail when:
browser does not support the API
page is not secure
permission is blocked
text is empty
user gesture is missing
Good UI expects failure.
Empty Content
If the editor is empty:
show Nothing to copy
do not write blank content silently
keep focus on the button
If the console is empty:
show Run code first
or Nothing in console
The message should tell the user what to do next.
Accessibility
Copy controls should include:
descriptive button label
visible focus state
status text for copied or failed
aria-live polite region if feedback is not visually adjacent
keyboard activation
touch-friendly target size
For repeated practice, small accessibility details become daily quality.
Toast Or Inline Feedback
Inline feedback is often better inside tools:
button text changes to Copied
small status appears in panel header
status clears after a short delay
Toast feedback is useful when:
the copy action is far from the visible button
multiple panels can trigger feedback
the UI already has a toast system
Do not introduce a full toast system only for one copy button unless the app will reuse it.
State Ownership
Keep copy feedback local to the panel:
code copy state belongs near editor
console copy state belongs near console
global toast belongs only if shared
This avoids one copy action overwriting another panel's feedback.
Testing Plan
Test:
copy code with content
copy console with content
empty code state
empty console state
clipboard failure path
button remains keyboard reachable
feedback resets after timeout
dark and light theme contrast
Mock the Clipboard API so tests can cover success and failure deterministically.
Common Mistakes
- Silently failing copy.
- Copying stale output.
- Copying blank content without feedback.
- Using only a mouse interaction.
- Not handling Clipboard API absence.
- Showing a toast that disappears too quickly.
- Letting copy feedback change layout size.
- Forgetting mobile tap targets.
Final Mental Model
Copy UX is:
clear target
safe text source
async handling
visible feedback
failure path
accessible control
Tiny workflows deserve real polish because users repeat them constantly.