Actions

Clipboard

A button that copies a value, or a field's or element's text, and shows and announces the copy.

Class nameTypeDescription
clipboardplf:clipboardComponentA copy button that draws a copy icon, and a check while the copy shows

Default

A click copies the text in data-plf-clipboard; for two seconds the label reads Copied and the icon a check.

Icon only

Without a label, the button shows its icon alone and needs aria-label.

#F5A623

From a field

data-plf-target names a field, whose value the button copies, or another element, whose text it copies.

JavaScript

Clipboard needs JavaScript. The Full script (pelatform-ui.min.js) starts every component on page load, with no code of your own; with ESM imports, call init() yourself, as in Installation. For markup you add later, see Dynamic content.

<link rel="stylesheet" href="pelatform-ui.min.css">
<script src="pelatform-ui.min.js" defer></script>
<link rel="stylesheet" href="pelatform-ui.prefixed.min.css">
<script src="pelatform-ui.min.js" defer></script>
Attribute Purpose
data-plf-clipboard On a <button>: the text to copy, or empty with data-plf-target
data-plf-target The id of an element in the same root: a field’s value or another element’s text is copied
data-plf-copied-label The label and announcement after a copy: Copied
data-plf-copy-error Announced when the browser refuses to copy: Copy failed. Select and copy the text.

The script adds a status (role="status") after the button, which announces each copy, and sets data-plf-state="copied" on the button for two seconds, which shows the check. A button with its own icon class first keeps that icon.

Methods

Method Behavior
PLF.Clipboard.getOrCreateInstance(button) Returns the instance, creating it for valid markup
PLF.Clipboard.getInstance(button) Returns the instance or null
instance.copy() Copies the text; resolves false when copying failed, another copy is running or the button is disabled
instance.destroy() Restores the label and removes listeners, the status and the copied state
Event When
plf:clipboard:copy After the text is on the clipboard
plf:clipboard:copy-error When the browser refuses to copy

Each event’s detail:

Property Value
instance The Clipboard instance
text The text it copied or tried to copy
reason trigger for a click, api for copy()
trigger The button, or null from copy()

React

Clipboard from @pelatform/react renders this button on a Button, with its status after it.

Prop Values Default
value The text a click copies Required
copiedLabel A text label’s place after a copy, and the announcement Copied
copyError The announcement when the browser refuses to copy Copy failed. Select and copy the text.
onCopy (text), called once the text is on the clipboard None

The other props are Button’s, className and ref included.


Built with Pelatform UIv0.1.0

Components

Getting started

Foundations

Components

Actions

Data display

Navigation

Feedback

Data input

Layout

Advanced

Integrations

Blocks

Application

Authentication

Icons