Allow disabling element
This commit is contained in:
Родитель
838e6637ac
Коммит
a17355909d
|
@ -8,6 +8,11 @@ async function copy(button: HTMLElement) {
|
|||
button.dispatchEvent(new CustomEvent('clipboard-copy', {bubbles: true}))
|
||||
}
|
||||
|
||||
if (button.getAttribute('aria-disabled') === 'true') {
|
||||
button.dispatchEvent(new CustomEvent('clipboard-copy-nothing', {bubbles: true}))
|
||||
return
|
||||
}
|
||||
|
||||
if (text) {
|
||||
await copyText(text)
|
||||
trigger()
|
||||
|
|
18
test/test.js
18
test/test.js
|
@ -62,6 +62,10 @@ describe('clipboard-copy element', function () {
|
|||
document.addEventListener('clipboard-copy', () => resolve(copiedText), {
|
||||
once: true,
|
||||
})
|
||||
|
||||
document.addEventListener('clipboard-copy-nothing', () => resolve(null), {
|
||||
once: true,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -149,6 +153,20 @@ describe('clipboard-copy element', function () {
|
|||
const text = await whenCopied
|
||||
assert.equal(text, 'I am a link')
|
||||
})
|
||||
|
||||
it('does not copy when disabled', async function () {
|
||||
const target = document.createElement('div')
|
||||
target.innerHTML = 'Hello world!'
|
||||
target.id = 'copy-target'
|
||||
document.body.append(target)
|
||||
|
||||
const button = document.querySelector('clipboard-copy')
|
||||
button.setAttribute('aria-disabled', 'true')
|
||||
button.click()
|
||||
|
||||
const text = await whenCopied
|
||||
assert.equal(null, text)
|
||||
})
|
||||
})
|
||||
|
||||
describe('shadow DOM context', function () {
|
||||
|
|
Загрузка…
Ссылка в новой задаче