SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

copyToClipboard

Copies text from an element a Message footer copy button's commandfor targets onto the system clipboard.

tsx
import { copyToClipboard } from "@sdxc/ui/mixins";

Usage

Writes the text content of a Message footer copy button's commandfor target onto the system clipboard, resolving the target fresh from the button on every press so it stays correct even as the DOM changes.

Signature

typescript
copyToClipboard(): MixinDescriptor<HTMLButtonElement>

Returns a mixin descriptor for a Message footer copy button's mix prop.

Examples

tsx
<div id="reply-1-content">{reply.text}</div>
<button
	type="button"
	commandfor="reply-1-content"
	command={COPY_COMMAND}
	aria-label={t("message.copy")}
	mix={[
		copyToClipboard(),
		on("ui:copy", (event) => {
			announce(event.success ? t("message.copied") : t("message.copyFailed"));
		}),
	]}
>
	<CopyIcon />
</button>

The events, constants and types its module publishes, each imported from @sdxc/ui/mixins too.

Event

CopyEvent

Dispatched on a Message footer copy button by copyToClipboard once a clipboard write settles, carrying success and the attempted text so consumers can render their own feedback for either outcome.

typescript
new CopyEvent(success: boolean, text: string)
PropertyTypeDefaultRequiredDescription
successreadonly boolean—Yestrue once the text reached the clipboard, false if the write was rejected or the platform API is unavailable.
textreadonly string—YesThe text copyToClipboard attempted to copy.
Constant

COPY_COMMAND

Custom Invoker Command a Message footer copy button declares via command={COPY_COMMAND} and commandfor, giving the pairing a genuine invoker relationship in markup, read by copyToClipboard on click.

typescript
const COPY_COMMAND = "--copy" as const
Constant

COPY_EXCLUDE_ATTRIBUTE

Attribute that keeps an element inside a copy target off the clipboard, together with the line break written right after it: a shell block's output lines, or the removed lines of a diff, stay on screen while the copied text is what a reader should paste.

typescript
const COPY_EXCLUDE_ATTRIBUTE = "data-copy-exclude"
@sdxc/ui

Can’t find it? Contact us