Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(v2): make accessible copy code button from keyboard #3588

Merged
merged 1 commit into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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