No description
  • JavaScript 62.2%
  • TypeScript 31.7%
  • Dockerfile 6.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jon Rohan 1feba66054
Merge pull request #88 from github/normalize-invisible-characters
Normalize invisible and whitespace characters on copy
2026-06-16 11:04:59 -07:00
.devcontainer Add a .devcontainer 2022-02-28 17:04:01 +00:00
.github/workflows Modify publish workflow to include id-token permission 2026-05-05 15:28:56 -07:00
examples [example] add announcement of text being copied 2023-10-23 16:53:45 +01:00
src Normalize invisible and whitespace characters on copy 2026-06-16 17:59:55 +00:00
test Normalize invisible and whitespace characters on copy 2026-06-16 17:59:55 +00:00
.eslintrc.json upgrade to new web component standards 2023-06-08 15:13:50 +01:00
.gitignore <clipboard-copy> 2018-02-27 15:20:01 -07:00
CODEOWNERS move AOR to primer 2022-09-23 18:20:13 +01:00
custom-elements.json upgrade to new web component standards 2023-06-08 15:13:50 +01:00
LICENSE <clipboard-copy> 2018-02-27 15:20:01 -07:00
package-lock.json v1.3.1 2026-06-15 10:07:26 -07:00
package.json v1.3.1 2026-06-15 10:07:26 -07:00
README.md Update link to polyfill 2020-10-31 16:20:29 +01:00
tsconfig.json upgrade to new web component standards 2023-06-08 15:13:50 +01:00
web-test-runner.config.js Fix test; start browser with clipboar-read perm 2023-09-28 10:34:37 -07:00

<clipboard-copy> element

Copy element text content or input values to the clipboard.

Installation

$ npm install --save @github/clipboard-copy-element

Usage

Script

Import as ES modules:

import '@github/clipboard-copy-element'

With a script tag:

<script type="module" src="./node_modules/@github/clipboard-copy-element/dist/index.js">

Markup

<clipboard-copy for="blob-path" class="btn btn-sm BtnGroup-item">
  Copy path
</clipboard-copy>
<div id="blob-path">src/index.js</div>

Data sources

Attribute

<clipboard-copy value="src/index.js">Copy</clipboard-copy>

Element content

<clipboard-copy for="blob-path">Copy</clipboard-copy>
<div id="blob-path">src/index.js</div>

Form input

<clipboard-copy for="blob-path">Copy</clipboard-copy>
<input id="blob-path" value="src/index.js">
<clipboard-copy for="blob-path">Copy full URL</clipboard-copy>
<a id="blob-path" href="/path/to#my-blob">Link text will not be copied</a>

Events

After copying to the clipboard, a clipboard-copy event is dispatched from the <clipboard-copy> element:

document.addEventListener('clipboard-copy', function(event) {
  const button = event.target
  button.classList.add('highlight')
})

Browser support

Browsers without native custom element support require a polyfill.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

Development

npm install
npm test

License

Distributed under the MIT license. See LICENSE for details.