shadcn.io is not affiliated with official shadcn/ui
Clipboard Denied Error Block for React
A panel for when the browser blocks copying: a read-only box that selects itself, Select all text, a Copy button that really tries the clipboard, the keys as words for Mac or Windows, and steps to allow it.
Installation
Overview
Let people finish the job when copying is blocked, with this clipboard denied panel for React with Base UI. It's the panel Snipdrawer, a snippet manager, shows when the page can't write to the clipboard: a heading and one sentence over one framed panel with a plus mark on each corner. The first band is a Field with a read-only Textarea holding a typed share link that selects itself when it takes focus. Under it the Shine Button "Select all text" really selects the text, and a Copy Button really tries the clipboard: if the browser refuses, a status line says "Your browser blocked it: copy by hand". A Segment Group chooses Mac or Windows and rewrites the keys to press as words in Kbd caps (Command C or Ctrl C), and a Collapsible folds away three steps for allowing clipboard access. A Switch in the header is a demo control that pretends the browser blocks copying. It is a fallback for a refused copy, not a copy button. For snippet, link-sharing and developer tools.
FAQ
What is real here, and what stays in the page?
Selecting is real: Select all text focuses the box and calls select(), so the keys then copy it. Copy is a real clipboard write when you press it with the demo switch off. Nothing is read from the clipboard, and the share link is a typed sample (LINK) that opens nothing. In your app, replace it with the text your user wants, and keep the status line: it is what tells them to copy by hand.
What does the Pretend my browser blocks copying switch do?
It is a demo control and it is on when the page opens, so the failure is what you see: with it on, Copy makes no attempt and the status line says it is pretending. Turn it off and Copy calls navigator.clipboard.writeText. Real browsers usually allow that after a press on a secure page, so you will most likely see "Copied to the clipboard"; to see a real refusal, open the page over plain http or inside a frame that blocks it.
Why would a browser refuse the clipboard at all?
The clipboard API only works on secure pages (https), usually only after a press or key, and a frame needs permission from the page that embeds it. Some browsers and some settings also block it per site. The steps in the folded section say how to check each, in order.
Are the keys detected?
No. The Mac and Windows control is a visible choice, defaulting to Mac, because guessing from the browser is unreliable and wrong for anyone on a shared or remote machine. The keys are written as words (Command, Ctrl) in key caps, so they read the same everywhere, and the choice never changes the page's height.
How does it work with the keyboard?
Tab reaches the box (and selects it), then Select all text, Copy, the Mac and Windows control and the folded section's button. The arrow keys move between Mac and Windows. Every result is spoken through one polite status line, and the box is named by its visible label.
Related
- Pro
Camera Denied Error
Browser and deviceA full-screen page for a blocked camera and microphone: what the app can use, a Check again that reads the permission state, a drawn address bar with its popover, and the steps for three browsers in tabs.
- Pro
Location Denied Error
Browser and deviceA full-screen page for blocked location: type a town instead, nine towns filtered as you type, three stores and their distances beside a drawn map, and a Check again that reads the permission state.
- Pro
Notification Denied Error
Browser and deviceA panel for blocked push notifications: two channel cells, Push (its state and the one-line fix, read from the browser) and Email instead, plus what the digest brings.
- Pro
Role Ladder Permission Denied Error
Locked and removedA full-screen permission page for a design-system manager: a role ladder of four rising steps with you at Viewer and Admin marked as needed, 'Two roles up' in words, and a Request access dialog that records a note and an owner in local state.
- Pro
Cookies Disabled Error
Browser and deviceA full-screen page for a browser with cookies off: a check that reads the browser and writes nothing, what four essential cookies hold, and the steps for three browsers in an accordion.
- Pro
Browser Unsupported Error
Browser and deviceA full-screen update-your-browser page with five real feature checks in a table (ES modules, CSS grid, :has(), WebGL, structuredClone), a Switch to pretend, and the browsers that have all five.