Skip to content

Commit 8ccb751

Browse files
authored
Refactor copy button to use success icon (#2024)
1 parent c63c69b commit 8ccb751

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

assets/css/copy-button.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ pre .copy-button:focus {
2424
font-size: 14px;
2525
line-height: 24px;
2626
color: currentColor;
27+
28+
& svg[aria-live="polite"] {
29+
display: none;
30+
}
2731
}
2832

2933
.copy-button svg {
@@ -43,6 +47,10 @@ pre .copy-button:focus-visible svg {
4347
.copy-button.clicked {
4448
opacity: 1;
4549
color: var(--success);
50+
51+
& svg[aria-live="polite"] {
52+
display: block;
53+
}
4654
}
4755

4856
.copy-button.clicked svg {

assets/js/copy-button.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ function initialize () {
2626

2727
let timeout
2828
button.addEventListener('click', () => {
29-
const ariaLiveContent = button.querySelector('[aria-live]')
3029
clearTimeout(timeout)
3130

3231
const text =
@@ -36,10 +35,10 @@ function initialize () {
3635

3736
navigator.clipboard.writeText(text)
3837
button.classList.add('clicked')
39-
ariaLiveContent.innerHTML = 'Copied! ✓'
38+
button.disabled = true
4039
timeout = setTimeout(() => {
4140
button.classList.remove('clicked')
42-
ariaLiveContent.innerHTML = ''
41+
button.disabled = false
4342
}, 3000)
4443
})
4544
})

assets/js/handlebars/templates/copy-button.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
<path d="M0 0h24v24H0z" fill="none"/>
44
<path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/>
55
</svg>
6-
<span aria-live="polite"></span>
6+
<svg aria-live="polite" role="img" aria-label="copied" viewBox="0 0 24 24" fill="currentColor">
7+
<path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" />
8+
</svg>
79
</button>

0 commit comments

Comments
 (0)