Skip to content

Commit

Permalink
refactor(v2): make accessible copy code button from keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 committed Oct 14, 2020
1 parent 5be3471 commit c6680c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

/* eslint-disable jsx-a11y/no-noninteractive-tabindex */

import React, {useEffect, useState, useRef} from 'react';
import clsx from 'clsx';
import Highlight, {defaultProps} from 'prism-react-renderer';
Expand Down Expand Up @@ -210,6 +208,7 @@ export default ({
)}
<div className={styles.codeBlockContent}>
<button
tabIndex={0}
ref={button}
type="button"
aria-label="Copy code to clipboard"
Expand All @@ -220,7 +219,6 @@ export default ({
{showCopied ? 'Copied' : 'Copy'}
</button>
<div
tabIndex={0}
className={clsx(className, styles.codeBlock, {
[styles.codeBlockWithTitle]: codeBlockTitle,
})}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@
color: var(--ifm-color-white);
cursor: pointer;
opacity: 0;
outline: none;
user-select: none;
padding: 0.4rem 0.5rem;
position: absolute;
right: calc(var(--ifm-pre-padding) / 2);
top: calc(var(--ifm-pre-padding) / 2);
visibility: hidden;
transition: opacity 200ms ease-in-out, visibility 200ms ease-in-out,
bottom 200ms ease-in-out;
transition: opacity 200ms ease-in-out;
}

.codeBlockTitle:hover + .codeBlockContent .copyButton,
.codeBlockContent:hover > .copyButton {
visibility: visible;
outline: none;
opacity: 1;
}

.copyButton:focus {
opacity: 1;
}

Expand Down

0 comments on commit c6680c6

Please sign in to comment.