Skip to content

Commit 4755da8

Browse files
authored
* fixes argyleink#18 * fixes argyleink#18 * Change copy button name to text node
1 parent df95a04 commit 4755da8

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/color-input.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,18 @@ export class ColorInput extends HTMLElement {
166166
// Copy to clipboard
167167
const copyBtn = this.#root.querySelector<HTMLButtonElement>('button.copy-btn')
168168
const copyMessage = this.#root.querySelector<HTMLElement>('.copy-message')
169-
if (copyBtn && copyMessage) {
169+
const copyMessageLiveRegion = this.#root.querySelector<HTMLElement>('.copy-message-live-region')
170+
if (copyBtn && copyMessage && copyMessageLiveRegion) {
170171
let copyTimeout: number | null = null
171172
copyBtn.addEventListener('click', async () => {
172173
try {
173174
await navigator.clipboard.writeText(this.#value.value)
174175
copyMessage.classList.add('show')
176+
copyMessageLiveRegion.innerText = copyMessage.innerText
175177
if (copyTimeout !== null) clearTimeout(copyTimeout)
176178
copyTimeout = window.setTimeout(() => {
177179
copyMessage.classList.remove('show')
180+
copyMessageLiveRegion.innerText = ""
178181
copyTimeout = null
179182
}, 3000)
180183
} catch {}

src/styles/index.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ button {
165165
white-space: nowrap;
166166
}
167167
.copy-message.show { opacity: 1; }
168+
169+
.visually-hidden:not(:focus):not(:active) {
170+
clip-path: inset(50%);
171+
height: 1px;
172+
overflow: hidden;
173+
position: absolute;
174+
white-space: nowrap;
175+
width: 1px;
176+
}
168177
}
169178

170179
/* Colorspace select: dropdown for switching color models (rgb, oklch, lab, etc.) */

src/utils/template.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ export function createTemplate(): HTMLTemplateElement {
2020
<div class="panel" popover="auto" part="panel">
2121
<div class="preview">
2222
<div class="copy-wrap">
23-
<button class="copy-btn" title="Copy color" aria-label="Copy color">
24-
<svg width="24" height="24" viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M5 22q-.825 0-1.413-.588T3 20V6h2v14h11v2H5Zm4-4q-.825 0-1.413-.588T7 16V4q0-.825.588-1.413T9 2h9q.825 0 1.413.588T20 4v12q0 .825-.588 1.413T18 18H9Z"/></svg>
23+
<button class="copy-btn">
24+
<span class="visually-hidden">Copy color</span>
25+
<svg width="24" height="24" viewBox="0 0 24 24" aria-hidden="true"><title>Copy color</title><path fill="currentColor" d="M5 22q-.825 0-1.413-.588T3 20V6h2v14h11v2H5Zm4-4q-.825 0-1.413-.588T7 16V4q0-.825.588-1.413T9 2h9q.825 0 1.413.588T20 4v12q0 .825-.588 1.413T18 18H9Z"/></svg>
2526
</button>
26-
<span class="copy-message" aria-live="polite" role="status">Copied!</span>
27+
<span class="copy-message" aria-hidden="true">Copied!</span>
28+
<span class="copy-message-live-region visually-hidden" role="status"></span>
2729
</div>
2830
<select class="space" title="Colorspace"></select>
2931
<output class="info" part="output"></output>

tests/unit/template.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ describe('template', () => {
6767
it('should include copy message', () => {
6868
const template = createTemplate()
6969
const copyMessage = template.content.querySelector('.copy-message')
70+
const copyMessageLiveRegion = template.content.querySelector('.copy-message-live-region')
7071
expect(copyMessage).not.toBeNull()
71-
expect(copyMessage?.getAttribute('aria-live')).toBe('polite')
72-
expect(copyMessage?.getAttribute('role')).toBe('status')
72+
expect(copyMessageLiveRegion?.getAttribute('role')).toBe('status')
7373
expect(copyMessage?.textContent).toBe('Copied!')
7474
})
7575

0 commit comments

Comments
 (0)