API REFERENCE · FORM CONTROLS
<dj-copy-button>
An icon-only button that copies text to the clipboard and shows whether it worked.
It is built on <dj-button>, so focus, keyboard use, and button semantics work as usual.
npm install @dojo-ng/copy-button
import "@dojo-ng/copy-button";
What it copies
- The literal
value, or, withfrom, the element with that id in the same root: itsvaluefor a form control, otherwise itstextContent. - When both
valueandfromare set,valuewins.
Feedback
- After a click, the icon changes to a check mark (copied) or an error mark for
feedback-durationmilliseconds, then changes back. - The accessible name changes with it (Copy, Copied, Copy failed), so screen reader users hear the result.
dj-copyfires with{ value }on success, anddj-erroron failure.
Requirements
- Copying uses
navigator.clipboard.writeText, which needs a secure context (https or localhost). There is no older fallback, so on plain http nothing is copied and the button shows its error state.
Properties
| Property | Attribute | Type | Default |
|---|---|---|---|
valueThe literal text to copy. Wins over from when both are set. |
value |
string |
"" |
fromId of an element in the same root to copy from (its value ?? textContent). |
from |
string |
None |
feedbackDurationHow long (ms) the success/error state shows before reverting to the copy icon. |
feedback-duration |
number |
2000 |
Events
| Event | Description |
|---|---|
dj-copy | detail { value } |
dj-error |
CSS parts
Style these with dj-copy-button::part(name).
| Part | Description |
|---|---|
button | the composed <dj-button> |
Methods
focus(options: FocusOptions)