Clipboard
Clipboard patterns for fast copy actions, safe sanitization, and clear feedback
Clipboard UX should be explicit and predictable. This page documents practical copy patterns, payload cleanup, and fallback behavior so users always know what was copied and when it succeeded.
1. Variant Matrix
Reusable clipboard variants for admin workflows
2. Clipboard Playground
Configure copy behavior on the left and inspect the final payload on the right
Plain payload with whitespace trimming enabled.
No copies yet.
3. Copy Rules
Make clipboard behavior deterministic and trustworthy
- Label copy targets clearly: key, URL, token, JSON payload.
- Preview transformed output before writing to clipboard.
- Confirm success quickly with non-blocking feedback.
- Handle rejected permission gracefully.
- Offer legacy fallback when Clipboard API is unavailable.
- Avoid silent failures in mission-critical workflows.
4. Sanitization
Normalize risky payloads before copying
Script tags are stripped and only safe text is copied to reduce clipboard risk in admin surfaces.
Valid JSON is pretty-printed for readability. Invalid JSON stays unchanged so no user data is lost.
5. Accessibility & Keyboard
Copy actions should stay clear for keyboard and assistive tech
Use short success/error messages and live regions so assistive technologies confirm copy completion.
Prefer labeled buttons instead of icon-only triggers for primary clipboard actions.
6. Real-use Snippets
Copy-ready clipboard utilities and fallback logic
async function copyValue(value) {
await navigator.clipboard.writeText(value);
}
function legacyCopy(value) {
const input = document.createElement('textarea');
input.value = value;
document.body.appendChild(input);
input.select();
document.execCommand('copy');
input.remove();
}
function sanitizeHtml(value) {
return value.replace(/