This commit is contained in:
Cameron Dutro 2023-09-27 10:45:55 -07:00
Родитель 838e6637ac
Коммит a17355909d
2 изменённых файлов: 23 добавлений и 0 удалений

Просмотреть файл

@ -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()

Просмотреть файл

@ -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 () {