CopyButton

Allow users to copy text to clipboard.

Note: This differs from the @navikt/ds-react implementation in that it uses the navigator.clipboard API instead of the document.execCommand("copy") API. This is to simplify code and support up-to-date browsers only. If you support IE or older browsers, reach out.

Properties

PropertyDescriptionDefault
Control
Properties
copyText
required

Text to copy to clipboard.

string
-
activeDuration

Timeout duration in milliseconds.

number
2000
activeText

Text shown when button is clicked. Only set if used with 'text'-prop.

string
""
activeTitle

Accessible label for icon in active-state (ignored if text is set).

string
"Copied"
iconPosition

Position of the icon

"left" "right"
"left"
size
"xsmall" "small" "medium" "medium"
text

Optional text in button.

string
""
title

Accessible label for icon (ignored if text is set).

string
"Copy"
variant
"action" "neutral" "neutral"
Snippets
icon

Use custom icons. The snippet receives the active-state as argument. Should only return a single icon.

 -
Events
activechanged

Called whenever the active-state changes

 -

Properties included from: HTMLButtonAttributes