Skip to content
Copy element text content or input values to the clipboard.
JavaScript TypeScript
Branch: master
Clone or download

Latest commit

muan Merge pull request #31 from github/eslint
Upgrade eslint-config-github
Latest commit ba705d4 May 28, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Only run on ubuntu-latest May 28, 2020
examples Convert to TypeScript May 21, 2020
src Add back HTMLElementTagNameMap defs May 22, 2020
test Fix github/no-then May 22, 2020
.eslintrc.json Include recommended rules May 26, 2020
.gitignore <clipboard-copy> Feb 27, 2018
CODEOWNERS Create CODEOWWNERS May 21, 2020
LICENSE <clipboard-copy> Feb 27, 2018
README.md Include script tag instruction May 21, 2020
package-lock.json Upgrade eslint-config-github May 22, 2020
package.json Upgrade eslint-config-github May 22, 2020
rollup.config.js Convert to TypeScript May 21, 2020
tsconfig.json Convert to TypeScript May 21, 2020

README.md

<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">

Hyperlink href

<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.

You can’t perform that action at this time.