Skip to main content

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
-
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
rootIdstring
The root ID of the component, used for hydration and identification.
No
-
idsarray
The IDs of of the component parts for composition.
No
[]
controlledboolean
If true, the component is meant to be initialized manually inside another component
No
false
classstring
The CSS class(es) to be applied to the component.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeclipboard
data-partroot
data-copiedPresent when copied state is true

clipboard.label

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

NameDescriptionRequiredDefault
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeclipboard
data-partlabel
data-copiedPresent when copied state is true

clipboard.control

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

NameDescriptionRequiredDefault
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeclipboard
data-partcontrol
data-copiedPresent when copied state is true

clipboard.input

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

NameDescriptionRequiredDefault
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeclipboard
data-partinput
data-copiedPresent when copied state is true
data-readonlyPresent when read-only

clipboard.trigger

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

NameDescriptionRequiredDefault
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeclipboard
data-parttrigger
data-copiedPresent when copied state is true

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
-
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Machine JavaScript API

NameTypeDescription
copiedbooleanWhether the value has been copied to the clipboard
valuestringThe value to be copied to the clipboard
setValue(value: string) => voidSet the value to be copied to the clipboard
copyVoidFunctionCopy the value to the clipboard

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>