Skip to content

Commit 6880564

Browse files
committed
fix: improve accessibility of copy button in README component
1 parent 481cceb commit 6880564

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

app/components/Readme.vue

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ const handleCopy = async (e: MouseEvent) => {
137137
.readme :deep(.readme-copy-button) {
138138
position: absolute;
139139
top: 0.4rem;
140-
right: 0.4rem;
141-
left: auto;
140+
inset-inline-end: 0.4rem;
142141
display: inline-flex;
143142
align-items: center;
144143
justify-content: center;
@@ -154,7 +153,8 @@ const handleCopy = async (e: MouseEvent) => {
154153
border-color 0.2s ease;
155154
}
156155
157-
.readme :deep(.readme-code-block:hover .readme-copy-button) {
156+
.readme :deep(.readme-code-block:hover .readme-copy-button),
157+
.readme :deep(.readme-copy-button:focus-visible) {
158158
opacity: 1;
159159
}
160160
@@ -179,8 +179,7 @@ const handleCopy = async (e: MouseEvent) => {
179179
.readme :deep(.readme-copy-button) {
180180
position: absolute;
181181
top: 0.4rem;
182-
right: 0.4rem;
183-
left: auto;
182+
inset-inline-end: 0.4rem;
184183
display: inline-flex;
185184
align-items: center;
186185
justify-content: center;
@@ -196,7 +195,8 @@ const handleCopy = async (e: MouseEvent) => {
196195
border-color 0.2s ease;
197196
}
198197
199-
.readme :deep(.readme-code-block:hover .readme-copy-button) {
198+
.readme :deep(.readme-code-block:hover .readme-copy-button),
199+
.readme :deep(.readme-copy-button:focus-visible) {
200200
opacity: 1;
201201
}
202202
@@ -421,4 +421,17 @@ const handleCopy = async (e: MouseEvent) => {
421421
margin: 0 0.25rem 0.25rem 0;
422422
border-radius: 4px;
423423
}
424+
425+
/* Screen reader only text */
426+
.readme :deep(.sr-only) {
427+
position: absolute;
428+
width: 1px;
429+
height: 1px;
430+
padding: 0;
431+
margin: -1px;
432+
overflow: hidden;
433+
clip: rect(0, 0, 0, 0);
434+
white-space: nowrap;
435+
border-width: 0;
436+
}
424437
</style>

server/utils/readme.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,10 @@ export async function renderReadmeHtml(
310310
renderer.code = ({ text, lang }: Tokens.Code) => {
311311
const html = highlightCodeSync(shiki, text, lang || 'text')
312312
// Add copy button
313-
return `<div class="readme-code-block" dir="ltr">
314-
<button type="button" class="readme-copy-button" title="Copy code" check-icon="i-carbon:checkmark" copy-icon="i-carbon:copy" data-copy>
313+
return `<div class="readme-code-block" >
314+
<button type="button" class="readme-copy-button" aria-label="Copy code" check-icon="i-carbon:checkmark" copy-icon="i-carbon:copy" data-copy>
315315
<span class="i-carbon:copy" aria-hidden="true"></span>
316+
<span class="sr-only">Copy code</span>
316317
</button>
317318
${html}
318319
</div>`

0 commit comments

Comments
 (0)