Skip to content

[@mantine/hooks] use-clipboard: Add rich content support - #9413

Draft
toofff wants to merge 3 commits into
mantinedev:masterfrom
toofff:use-clipboard-rich-content
Draft

toofff wants to merge 3 commits into
mantinedev:masterfrom
toofff:use-clipboard-rich-content

Conversation

@toofff

@toofff toofff commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Hello 👋 , this is my first PR here. I haven't created an issue for this change, but if it's important for the process, please let me know, and I'll create an issue and leave this PR as a draft.

useClipboard().copy and CopyButton value now accept rich content, so formatted text and tables keep their formatting when pasted in Google Docs, Gmail or Slack, and stay clean plain text in a plain text editor.

type ClipboardValue = string | { text: string; html?: string };

copy(value: ClipboardValue | (() => ClipboardValue)): void;
<CopyButton value={() => ({ html: ref.current!.innerHTML, text: ref.current!.innerText })}>
  {({ copied, copy }) => ...}
</CopyButton>
  • A string is copied with writeText, as before
  • An object with html is copied with clipboard.write as both text/html and text/plain
  • An object without html, or a browser without ClipboardItem / clipboard.write, falls back to writeText(text)
  • A function is called at the moment of copying, which is useful when the value is read from the DOM
  • clipboard.write is called synchronously in copy, which is required by Safari
  • copied and error follow the result of the write, including the reset of copied on error from [@mantine/hooks] use-clipboard: Reset copied state on error #9310
  • ClipboardValue and ClipboardRichValue types are exported from @mantine/hooks

Note: copy was typed as (value: any) => void, it is now typed with ClipboardValue. Runtime behavior for strings does not change, but TypeScript code passing a non-string value will need a String() conversion.

Tests: new use-clipboard tests (string, rich content, fallbacks, function value, errors, timeout) and CopyButton tests.

Docs: "Rich content" and "Copy value on click" sections on the use-clipboard page, "Rich content" section on the CopyButton page, new demos and Storybook stories.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant