Search docs

Clipboard

Copy-to-clipboard button with live region announcement and optional read-only input.

There is no WAI-ARIA APG pattern for clipboard controls. Clipboard uses a native <button type="button"> for the trigger and announces copy confirmation through a polite live region.

import { component$, useStyles$ } from '@builder.io/qwik';
import { Clipboard } from '@leve-ui/clipboard';
import { LuCheck, LuCopy } from '@qwikest/icons/lucide';
import styles from './default.css?inline';

export default component$(() => {
  useStyles$(styles);

  return (
    <Clipboard.Root value="pnpm add @leve-ui/clipboard" class="clipboard-default">
      <Clipboard.Input class="clipboard-default-input" aria-label="Install command" />
      <Clipboard.Trigger class="clipboard-default-trigger" aria-label="Copy to clipboard">
        <Clipboard.Indicator class="clipboard-default-indicator">
          <LuCopy class="clipboard-default-icon clipboard-default-icon-idle" aria-hidden="true" />
          <LuCheck
            class="clipboard-default-icon clipboard-default-icon-copied"
            aria-hidden="true"
          />
        </Clipboard.Indicator>
      </Clipboard.Trigger>
    </Clipboard.Root>
  );
});

Installation#

Install the individual package, or use @leve-ui/core to get every component at once:

pnpm add @leve-ui/clipboard

Anatomy#

import { Clipboard } from '@leve-ui/clipboard'; // or '@leve-ui/core'

<Clipboard.Root value="https://leve-ui.dev">
  <Clipboard.Input />
  <Clipboard.Trigger>
    <Clipboard.Indicator />
  </Clipboard.Trigger>
</Clipboard.Root>
PartElementDescription
Clipboard.Root<div>Holds the value to copy, manages the timed copied state, and announces copy confirmation.
Clipboard.Trigger<button>Button that copies the value to the clipboard when activated.
Clipboard.Indicator<span>Visual indicator (aria-hidden="true") reflecting the current idle or copied state.
Clipboard.Input<input>Optional read-only input displaying the value to copy.

Examples#

Button only#

Omit Clipboard.Input when only a copy button is needed.

Custom timeout#

Pass timeout (in milliseconds) to control how long data-state="copied" remains active.

API Reference#

Root#

PropDefaultType
value (required)–string

The text value to copy to the clipboard.

timeout2000number

Duration in milliseconds before copied resets to false.

copiedAnnouncement'Copied to clipboard'string

Message announced to screen readers via the live region when copied.

onCopy$–QRL<(value: string) => void>

Callback invoked with the copied value when copying succeeds.

onStatusChange$–QRL<(copied: boolean) => void>

Callback invoked when the copied state changes.

Also accepts all <div> attributes.

Data attributeValue
data-leve-clipboardAlways present
data-state"idle" | "copied"
data-copiedPresent when copied

Trigger#

No props of its own. Accepts all <button> attributes.

Data attributeValue
data-leve-clipboard-triggerAlways present
data-state"idle" | "copied"
data-copiedPresent when copied

Indicator#

No props of its own. Accepts all <span> attributes.

Data attributeValue
data-leve-clipboard-indicatorAlways present
data-state"idle" | "copied"
data-copiedPresent when copied

Input#

No props of its own. Accepts all <input> attributes.

Data attributeValue
data-leve-clipboard-inputAlways present
data-state"idle" | "copied"
data-copiedPresent when copied

Accessibility#

  • Clipboard.Trigger renders a native <button type="button">, supporting activation with Enter and Space. Provide an accessible name via visible text or aria-label.
  • Clipboard.Indicator sets aria-hidden="true" so decorative icons are not read by screen readers.
  • When copying succeeds, Clipboard.Root announces copiedAnnouncement (default "Copied to clipboard") via a polite live region (announce() from @leve-ui/utils).
  • Clipboard.Input sets readOnly so users can inspect or manually select the text without modifying it; give it an aria-label or associate a <label> when used.