Skip to main content

Clipboard

A component to copy text to the clipboard.

Features

Installation

typo3 ui:add clipboard

Read more about installing Components and Primitives.

Examples

Copy Button Only

Display only a copy button without the input field.

Custom Timeout

Set a custom duration for how long the "copied" state is shown.

Localization

Default clipboard trigger labels are shipped via XLF and follow the current Site Language. For per-template overrides, pass translated strings through the translations prop. Set a translation entry to {false} or an empty string to omit the corresponding aria-label.

Note that Zag.js uses a function for the trigger label to allow dynamic labels based on the copied state. Fluid Primitives simplifies this by accepting static strings for both states, which are then merged into the appropriate function internally.

<f:variable
    name="clipboardTranslations"
    value="{
        triggerLabelIdle: '{f:translate(key: \'LLL:EXT:site_package/Resources/Private/Language/locallang.xlf:clipboard.copy\')}',
        triggerLabelCopied: '{f:translate(key: \'LLL:EXT:site_package/Resources/Private/Language/locallang.xlf:clipboard.copied\')}'
    }"
/>

<ui:clipboard.root value="Copy me" translations="{clipboardTranslations}"> ... </ui:clipboard.root>

API Reference

The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.

clipboard.root

Provides the clipboard state and shared context for the composed parts. Renders a <div> element.

NameDescriptionRequiredDefault
valuestring
The value to copy to the clipboard.
Yes
-
timeoutinteger
The timeout for the copied state in milliseconds.
No
3000
translationsarray
Localized clipboard trigger labels. Set entries to `` to omit the corresponding `aria-label`. Use `f:translate` for per-template localization overrides when needed.
No
-

clipboard.label

Labels the clipboard input. Renders a <label> element.

clipboard.control

Groups the input and trigger into a single layout container. Renders a <div> element.

clipboard.input

Displays the text value that can be copied. Renders an <input> element.

clipboard.trigger

Copies the current value to the clipboard when activated. Renders a <button> element.

clipboard.indicator

Displays UI for a specific clipboard state like idle or copied. Renders a <span> element.

NameDescriptionRequiredDefault
stateEnum\ClipboardIndicatorState
The indicator state to render.
Yes
-

Anatomy

<primitives:clipboard.root>
    <primitives:clipboard.label />
    <primitives:clipboard.control>
        <primitives:clipboard.input />
        <primitives:clipboard.trigger>
            <primitives:clipboard.indicator />
        </primitives:clipboard.trigger>
    </primitives:clipboard.control>
</primitives:clipboard.root>