Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ember-cli-clipboard

jkusa103.3kMIT1.3.0TypeScript support: included

Clipboard.js button component

ember-addon, ember-cli, clipboard

readme

ember-cli-clipboard

Downloads Build Status Ember Observer Score

A simple ember wrapper around clipboard.js (no flash)

Demo Page

http://jkusa.github.io/ember-cli-clipboard

Usage

CopyButton Component

<!-- Set text directly -->
<CopyButton
  @text='text to be copied'
  @onSuccess={{this.onSuccess}}
  @onError={{this.onError}}
>
  Click To Copy
</CopyButton>

<!-- Get text from action that returns a string -->
<CopyButton
  @text={{this.getText}}
  @onSuccess={{this.onSuccess}}
  @onError={{this.onError}}
>
  Click To Copy
</CopyButton>

<!-- Get text from target element -->
<input
  id='url'
  type='text'
  value='https://github.com/jkusa/ember-cli-clipboard'
/>
<CopyButton
  @target='#url'
  @onSuccess={{this.onSuccess}}
  @onError={{this.onError}}
>
  Click To Copy
</CopyButton>

Arguments

  • text - string value or action that returns a string to be copied
  • target - selector string of element or action that returns an element from which to copy text
  • action - string value of operation: copy or cut (default is copy)
  • container - selector string or element object of containing element. "For use in Bootstrap Modals or with any other library that changes the focus you'll want to set the focused element as the container value".
  • delegateClickEvent - clipboard.js defaults event listeners to the body in order to reduce memory footprint if there are hundreds of event listeners on a page. If you want to scope the event listener to the copy button, set this property to false
  • buttonType - string value of the button's type attribute (for Ember < 3.25.x, see below)

Any HTML button attribute passed to the component will be "splatted" on the button element. The one exception to this is the type attribute due to this issue < Ember 3.25.x.

Actions

The following clipboard.js custom events are sent as actions

  • onSuccess sent on successful copy
  • onError sent on failed copy

More information about the clipboard.js events can be found here

Clipboard Element Modifier

Under the hood the <CopyButton> component is powered by a {{clipboard}} element modifier. This can be used directly as an alternative to the <CopyButton> component. It has the same argument contract as the <CopyButton> component except for the exclusion of the buttonType argument.

<button
  class='button is-outline'
  type='button'
  {{clipboard text='text to be copied' onSuccess=this.onSuccess}}
>
  Click To Copy
</button>

Template Helper

The helper is-clipboard-supported can be used to check if clipboard.js is supported or not.

{{#if (is-clipboard-supported)}}
  <CopyButton @target='#url'>
    Click To Copy
  </CopyButton>
{{/if}}

Test Helpers

Some browsers do not allow simulated clicks to fire execCommand('copy'). This makes testing difficult. To assist with integration testing, the following test helpers are available to test the wiring of the success and error action handlers.

Acceptance Test Helpers

  • triggerCopySuccess(selector='.copy-btn')
  • triggerCopyError(selector='.copy-btn')
// tests/acceptance/my-test.js

import {
  triggerCopyError,
  triggerCopySuccess,
} from 'ember-cli-clipboard/test-support';

Example:

// tests/acceptance/my-test.js

test('copy button message', async function (assert) {
  assert.expect(3);

  await visit('/');
  assert.dom('.alert').doesNotExist('no alert message is initially present');

  triggerCopySuccess();

  assert
    .dom('.alert.alert-success')
    .exists('a success message is displayed when a copy is successful');

  triggerCopyError();

  assert
    .dom('.alert.alert-info')
    .exists('an error message is displayed when a copy is unsuccessful');
});

Integration Test Helpers

  • triggerCopySuccess(selector='.copy-btn')
  • triggerCopyError(selector='.copy-btn')

Example:

// tests/integration/components/my-test.js

// if using NEW ember testing api
import {
  triggerCopyError,
  triggerCopySuccess,
} from 'ember-cli-clipboard/test-support';

test('copy-button integration', async function (assert) {
  assert.expect(2);

  this.set('onSuccess', () => {
    assert.ok(true, '`success` action handler correctly fired');
  });

  this.set('onError', () => {
    assert.ok(true, '`error` action handler correctly fired');
  });

  await render(hbs`
    <CopyButton
      class="my-copy-btn"
      @text="text to be copied"
      @onSuccess={{this.onSuccess}}
      @onError={{this.onError}}
    >
      Click To Copy
    </CopyButton>
  `);

  //If using NEW ember testing api
  triggerCopyError('.my-copy-btn');
  triggerCopySuccess('.my-copy-btn');
});

Browser Support

For browser support information, checkout the clipboard.js documentation:

https://github.com/zenorocha/clipboard.js/#browser-support

Contributing

Contributions are welcomed. Please read the contributing guidelines.

License

This project is licensed under the MIT License.

changelog

1.3.0 (2025-03-15)

  • build(deps-dev): bump webpack from 5.76.0 to 5.95.0 (#419) (089528e), closes #419
  • build(deps): bump @babel/helpers from 7.22.10 to 7.26.10 (#425) (9c38066), closes #425
  • build(deps): bump cross-spawn (#424) (618dc07), closes #424
  • build(deps): bump express from 4.19.2 to 4.21.2 (#427) (ef9c13b), closes #427
  • build(deps): bump semver (#428) (88d74df), closes #428
  • chore: add type declarations (#423) (7379070), closes #423

1.2.1 (2024-10-23)

  • fix: move @ember/test-helpers to dependencies (#420) (7f63845), closes #420
  • Bump ws, engine.io and socket.io-adapter (5de68e2)

1.2.0 (2024-07-20)

  • refactor: remove use of @ember/string (5dbca8e), closes #409
  • Bump @babel/traverse from 7.22.10 to 7.23.2 (#403) (63c624f), closes #403
  • Bump browserify-sign from 4.2.1 to 4.2.2 (#404) (ad919eb), closes #404
  • Bump engine.io and socket.io (#398) (42e776f), closes #398
  • Bump express from 4.18.2 to 4.19.2 (#408) (55452c9), closes #408
  • Bump follow-redirects from 1.15.2 to 1.15.6 (#407) (8b1b85b), closes #407
  • Bump http-cache-semantics from 4.1.0 to 4.1.1 (#387) (77c2f6d), closes #387
  • Bump markdown-it and ember-cli (#395) (6d6a9f8), closes #395
  • Bump minimist from 0.2.2 to 0.2.4 (#389) (cc674a0), closes #389
  • Bump postcss from 8.4.18 to 8.4.31 (#402) (ea13a05), closes #402
  • Bump socket.io-parser from 4.2.1 to 4.2.4 (#399) (4544a0f), closes #399
  • Bump tough-cookie from 4.1.2 to 4.1.3 (#401) (1c916dc), closes #401
  • Bump webpack from 5.74.0 to 5.76.0 (#392) (70d8a7f), closes #392
  • Bump word-wrap from 1.2.3 to 1.2.5 (#400) (43c8863), closes #400

1.1.0 (2023-08-22)

  • chore: support ember-modifier 3.x and 4.x (e398557), closes #396
  • Bump decode-uri-component from 0.2.0 to 0.2.2 (#385) (1f79ea4), closes #385
  • Bump engine.io from 6.2.0 to 6.2.1 (#384) (3fc748a), closes #384
  • Bump loader-utils from 1.4.1 to 1.4.2 (#383) (55e7f95), closes #383

1.0.0 (2022-11-22)

  • Bump loader-utils from 1.4.0 to 1.4.1 (#382) (f654bdc), closes #382
  • build: move ember-modifer to dependencies (#381) (87bb0cb), closes #381
  • feat: support target to be set dynamically (#379) (66bf3a7), closes #379
  • feat: support direct use of the clipboard modifier (7e3f448)
  • chore: make changelog with conventional-changelog-cli (#378) (fae8d89), closes #378
  • chore: make repo commitizen friendly (#371) (0b2eede), closes #371
  • chore: simplify demo component (3169422)
  • chore: update ember-auto-import to v2 & ember-cli v4 (#370) (8e1aa28), closes #370

BREAKING CHANGE

  • This commit contains many breaking changes:

    • Drops ember classic component support (glimmer only)
    • Drops support for sendAction
    • Requires ember-auto-import 2.x
    • <CopyButton> component arg name changes:

    | Old Argument Name | New Argument Name | | ------------------ | -------------------------------------- | | @clipboardText | @text | | @clipboardTarget | @target | | @clipboardAction | @action | | @success | @onSuccess | | @error | @onError | | @title | no longer supported, pass as attribute | | @disabled | no longer supported, pass as attribute | | @aria-label | no longer supported, pass as attribute |

0.16.0 (2021-11-15)

  • [Security] Bump elliptic from 6.5.2 to 6.5.3 (#233) (6215398), closes #233
  • [Security] Bump highlight.js from 10.3.2 to 10.4.1 (#290) (262a525), closes #290
  • [Security] Bump websocket-extensions from 0.1.3 to 0.1.4 (#211) (bf84751), closes #211
  • 0.16.0 (0b3cc4d)
  • Bump ember-angle-bracket-invocation-polyfill from 2.1.0 to 3.0.0 (#264) (33fd884), closes #264
  • Bump ember-cli-flash from 1.9.1 to 2.1.0 (#295) (53d0497), closes #295
  • Bump ember-cli-terser from 4.0.0 to 4.0.1 (#273) (5489dde), closes #273
  • Bump ember-composable-helpers from 2.4.0 to 4.3.0 (#248) (8be6374), closes #248
  • Bump ember-modifier from 1.0.5 to 2.1.1 (#254) (8b5277b), closes #254
  • Bump ember-template-lint from 2.12.1 to 2.13.0 (#256) (13247b7), closes #256
  • Bump ember-template-lint from 2.7.0 to 2.8.0 (#202) (ebe9854), closes #202
  • Bump eslint from 7.10.0 to 7.12.0 (#274) (78f1cff), closes #274
  • Bump eslint from 7.13.0 to 7.16.0 (#296) (3bb16f0), closes #296
  • Bump eslint from 7.9.0 to 7.10.0 (#257) (66cb77a), closes #257
  • Bump eslint-plugin-ember from 8.4.0 to 8.7.0 (#217) (0bcb927), closes #217
  • Bump eslint-plugin-ember from 8.7.0 to 9.0.0 (#250) (12b61a4), closes #250
  • Bump eslint-plugin-ember from 9.0.0 to 9.1.1 (#258) (066d665), closes #258
  • Bump highlight.js from 10.2.0 to 10.3.1 (#270) (8b910e2), closes #270
  • Bump ini from 1.3.5 to 1.3.8 (#294) (e9f4c36), closes #294
  • Bump prettier from 2.1.2 to 2.2.1 (#288) (4e344ae), closes #288
  • Bump pretty-quick from 2.0.2 to 3.0.2 (#255) (aa858a0), closes #255
  • Bump qunit-dom from 1.5.0 to 1.6.0 (#281) (76c2b89), closes #281
  • Bump sass from 1.26.11 to 1.27.0 (#267) (1e7cbb3), closes #267
  • Bump sass from 1.26.5 to 1.26.8 (#214) (54e1860), closes #214
  • Bump uuid from 8.3.0 to 8.3.1 (#259) (ed7bb5d), closes #259
  • Ember 3.25 (#337) (76791d5), closes #337
  • relax @ember/render-modifiers dependency (#367) (7fe04ef), closes #367
  • Rename default branch to main (e27143f)
  • Update build badge (dedab51)
  • Update lock file (e7e4112)
  • Update uuid and highlight.js (#253) (3338133), closes #253
  • Upgrade to ember 3.21 (#252) (82325c6), closes #252
  • Upgrade to ember 3.22 (#277) (b227719), closes #277
  • Upgrade to ember 3.28 (#368) (843b0d7), closes #368
  • ci: migrate to github actions (#333) (3937af4), closes #333

0.15.0 (2020-06-24)

  • [Security] Bump acorn from 5.7.3 to 5.7.4 (98ad16c)
  • 0.15.0 (66b1caf)
  • Add ClipboardJS container support (#206) (9734d8f), closes #206
  • Bump babel-eslint from 10.0.3 to 10.1.0 (80a8dbb)
  • Bump broccoli-funnel from 1.2.0 to 3.0.1 (312eb16)
  • Bump broccoli-funnel from 3.0.1 to 3.0.2 (cd66087)
  • Bump clipboard from 2.0.4 to 2.0.6 (4701be9)
  • Bump ember-angle-bracket-invocation-polyfill from 1.3.1 to 2.0.2 (aa515d2)
  • Bump ember-cli from 3.15.1 to 3.15.2 (91cf7f5)
  • Bump ember-cli-babel from 7.13.2 to 7.14.1 (5c06041)
  • Bump ember-cli-babel from 7.14.1 to 7.17.2 (6267e36)
  • Bump ember-cli-fastboot from 2.2.1 to 2.2.2 (4276fe9)
  • Bump ember-cli-fastboot-testing from 0.2.4 to 0.4.0 (eaf4dce)
  • Bump ember-cli-flash from 1.8.0 to 1.8.1 (5f585a5)
  • Bump ember-cli-htmlbars from 4.2.0 to 4.2.2 (6619d67)
  • Bump ember-cli-template-lint from 1.0.0-beta.3 to 2.0.0 (2964077)
  • Bump ember-cli-template-lint from 2.0.0 to 2.0.2 (19cdba1)
  • Bump ember-decorators-polyfill from 1.1.1 to 1.1.2 (c7a4562)
  • Bump ember-decorators-polyfill from 1.1.2 to 1.1.3 (9826dbb)
  • Bump ember-decorators-polyfill from 1.1.3 to 1.1.5 (6cac62e)
  • Bump ember-modifier from 1.0.2 to 1.0.3 (3546a4b)
  • Bump ember-source from 3.15.0 to 3.16.0 (dc77e8c)
  • Bump ember-source from 3.16.0 to 3.16.1 (3116360)
  • Bump ember-source from 3.16.1 to 3.16.3 (6f5ed8e)
  • Bump ember-template-lint from 2.5.2 to 2.7.0 (99b6d29)
  • Bump eslint from 6.8.0 to 7.0.0 (143c808)
  • Bump eslint-plugin-ember from 7.10.1 to 8.4.0 (c22133c)
  • Bump eslint-plugin-ember from 7.8.1 to 7.9.0 (20cb8fd)
  • Bump eslint-plugin-ember from 7.9.0 to 7.10.1 (43e62d4)
  • Bump eslint-plugin-node from 11.0.0 to 11.1.0 (97512fb)
  • Bump highlight.js from 9.17.1 to 9.18.1 (b8b1507)
  • Bump husky from 3.1.0 to 4.2.1 (50d0a93)
  • Bump husky from 4.2.1 to 4.2.3 (047c4db)
  • Bump husky from 4.2.3 to 4.2.5 (74b267b)
  • Bump prettier from 1.19.1 to 2.0.2 (9a24396)
  • Bump prettier from 2.0.2 to 2.0.4 (f07002f)
  • Bump prettier from 2.0.4 to 2.0.5 (00eddc8)
  • Bump qunit-dom from 0.9.2 to 1.0.0 (ac266b5)
  • Bump qunit-dom from 1.0.0 to 1.1.0 (abcf2a2)
  • Bump sass from 1.24.3 to 1.25.0 (3dc2353)
  • Bump sass from 1.25.0 to 1.26.3 (f6a2308)
  • Bump sass from 1.26.3 to 1.26.5 (d3a12c6)
  • Bump uuid from 3.3.3 to 3.4.0 (4a70080)
  • Bump uuid from 3.4.0 to 7.0.1 (22e1e7b)
  • Bump uuid from 7.0.1 to 7.0.2 (3fc421d)
  • Bump uuid from 7.0.2 to 7.0.3 (3fab5b1)
  • Fix for clean-css vulnerability (d1dfb82)
  • Run prettier 2.x on project (6290e88)
  • Update lock file for Ember v3.17.0 (96cd955)
  • Update README.md (2b99825)
  • Upgrade ember-cli-babel (a9b5c72)
  • Upgrade to Ember v3.17.0 (0a38cd6)
  • Upgrade to ember-cli 3.16 (215c983)
  • Use ember-auto-import to bring in ClipboardJS (0678c5b)
  • Update: Don't use optional chaining for fastboot (#218) (4af026c), closes #218

0.14.0 (2020-01-16)

  • 0.14.0 (27b5833)
  • Add deploy script (b6544ed)
  • Bump eslint-plugin-node from 9.2.0 to 11.0.0 (0e8ec62)
  • Bump pretty-quick from 1.11.1 to 2.0.1 (09d1857)
  • Create stale.yml (c62b286)
  • Update ember-angle-bracket-invocation-polyfill requirement (5456aa3)
  • Update husky requirement from ^2.3.0 to ^3.0.0 (6883757)
  • Update issue templates (a1d8ee9)
  • Update issue templates (a756e9f)
  • Upgrade to Ember 3.15 (e91952d)

0.13.0 (2019-07-02)

  • 0.13.0 (bfbe82b)
  • Allow copy text to be set by an action (4ad72ba)
  • refactor acceptance test and update README (a904c2e)

0.12.0 (2019-06-18)

0.11.1 (2019-01-08)

0.11.0 (2019-01-02)

  • 0.10.0 (5177297)
  • 0.11.0 (600f898)
  • clean up bower (#41) (6008a22), closes #41
  • Get rid of font-awesome (#42) (4a61f6b), closes #42
  • Provide forward compatibility when accessing container (#38) (f3ea071), closes #38
  • Upgrade to ember-cli 3.6 (#49) (58c5e39), closes #49
  • Use ember-auto-import for dummy app (#43) (396f161), closes #43

0.9.0 (2018-03-28)

0.8.1 (2017-11-07)

0.8.0 (2017-07-08)

  • 0.8.0 (1b06029)
  • Add fastboot as dev dependency for dummy app (55df627)
  • Bump clipboard.js to 1.7.1 (e4ca15e)
  • Make this addon FastBoot compatible (a0bba57)
  • Update to ember-cli-2.13.3 (236ee97)

0.7.0 (2017-05-20)

  • 0.7.0 (3e016b8)
  • Add aria-label attribute. (843536c)
  • Add documentation for button attribute properties (2d8b6f0)

0.6.0 (2017-05-16)

  • 0.6.0 (5f56d8e)
  • Add a helper to check clipboard.js is supported or not (7f37020)
  • Add another example to demonstrate the helper (702ca84)
  • Add tests to verify the helper is registered correctly (77e0375)
  • Bind the title attribute (3b247c3)
  • Correct syntax highlighting in README (a4923aa)
  • Remove dummy.css from tests/index.html (7d41688)
  • Update documentation (4ab6f2a)
  • Update ember-cli-github-pages to v0.1.2 (2d31e5f)
  • Use clipboard 1.6.0 or later to use Clipboard.isSupported() (f8f64ef)

0.5.0 (2017-01-20)

  • 0.5.0 (361d59f)
  • Add code-block dummy app component (f2c39c1)
  • Add test helpers (b1a18ba)
  • Fix startApp for older ember versions (9f1604e)
  • Update README.md (0466fa1)
  • Upgrade to ember-cli-2.10.0 (629b604)
  • Use closure actions in dummy app (cd08add)

0.4.1 (2016-08-02)

  • 0.4.1 (975e1b9)
  • Remove deprecation warnings. Update ember-cli-htmlbars. (3335e22)

0.4.0 (2016-06-16)

0.3.2 (2016-04-12)

0.3.1 (2016-03-10)

  • Don’t add clipboard.js when running under Fastboot (87645d1)
  • Released v0.3.1 (b8c46e4)
  • Released v0.3.1 (d4c03a7)
  • Released v0.4.0 (dc471a3)
  • Upgrade ember-qunit to 0.4.16 (f25a2e5)
  • Upgrade to ember-cli 2.4.2 (7cc7eeb)

0.3.0 (2015-11-26)

0.2.1 (2015-10-22)

0.1.0 (2015-10-07)