Skip to main content

A button that copies a value to the clipboard, with an optional input that shows it.

<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>
typo3 ui:add clipboard

Read more about installing Components and Primitives.

Leave out the input for a copy button on its own. The demo copies a share link.

Set timeout in milliseconds to change how long the copied state stays. The button in the demo reads "Copied for 5 seconds!" for timeout="5000".

The trigger labels for the idle and the copied state ship in the language file and follow the site language. Pass translations with one string per state to override them for one clipboard.

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

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

A client script passes a triggerLabel function of the copied state instead of the two strings.

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.

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, `triggerLabelIdle` and `triggerLabelCopied`. A client script can pass a `triggerLabel` function of the copied state instead. Use `f:translate` for per-template localization overrides when needed.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
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
[]
autoMountboolean
Whether the client initializes the component on its own. Set it to false to mount it yourself with `mount()`
No
true
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-clipboard-root<uid>
data-copiedPresent when copied state is true

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

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
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
-

Rendered data attributes

AttributeDescription
data-clipboard-label<uid>
data-copiedPresent when copied state is true

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

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
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
-

Rendered data attributes

AttributeDescription
data-clipboard-control<uid>
data-copiedPresent when copied state is true

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

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
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
-

Rendered data attributes

AttributeDescription
data-clipboard-input<uid>
data-copiedPresent when copied state is true
data-readonlyPresent when read-only

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

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
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
-

Rendered data attributes

AttributeDescription
data-clipboard-trigger<uid>
data-copiedPresent when copied state is true

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

NameDescriptionRequiredDefault
stateEnum\ClipboardIndicatorState
The indicator state to render.
Yes
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
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
-
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
getIndicatorState(props: IndicatorProps) => IndicatorStateReturns the state of the indicator