zenorocha / clipboard.js

:scissors: Modern copy to clipboard. No Flash. Just 3kb gzipped :clipboard:
https://clipboardjs.com
MIT License
33.98k stars 3.98k forks source link

Regression in 2.0.9 leading to values other than type string (number, boolean) cannot be copied #873

Open tasso94 opened 5 months ago

tasso94 commented 5 months ago

🐛 Bug Report

See the following example:

new ClipboardJS(document.getElementsByClassName("btn"), {
  text: function() {
    return 900;
  }
});

Expected Behaviour

When text() returns another value type than string, no error is shown and value is stored in the clipboard.

Actual Behaviour

When text() returns another value type than string, the following error is shown:

Uncaught TypeError: element.hasAttribute is not a function
    at select (clipboard.js:717:1)
    at ClipboardActionCopy (clipboard.js:117:1)
    at ClipboardActionDefault (clipboard.js:166:1)
    at Clipboard.onClick (clipboard.js:290:1)
    at HTMLAnchorElement.<anonymous> (clipboard.js:278:1)

To Reproduce

Check out the following JS Riddle: https://jsfiddle.net/L6ptjo7w/

Browsers Affected

I tested it on Chrome 123.

Operational System

Mac OS Ventura.

obetomuniz commented 2 months ago

Thanks for reporting this @tasso94. And thanks to provide a reproducible environment. I'm planning to contribute to some open issues soon. I will be triaging it. Thanks again.

tasso94 commented 2 months ago

Hi @obetomuniz,

That would be awesome. Thanks 👍