mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-22 21:47:01 +02:00
refactor(v2): make accessible copy code button from keyboard (#3588)
This commit is contained in:
parent
aed1ce7850
commit
fe7267ae93
2 changed files with 8 additions and 8 deletions
|
@ -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';
|
||||
|
@ -210,6 +208,7 @@ export default ({
|
|||
)}
|
||||
<div className={styles.codeBlockContent}>
|
||||
<button
|
||||
tabIndex={0}
|
||||
ref={button}
|
||||
type="button"
|
||||
aria-label="Copy code to clipboard"
|
||||
|
@ -220,7 +219,6 @@ export default ({
|
|||
{showCopied ? 'Copied' : 'Copy'}
|
||||
</button>
|
||||
<div
|
||||
tabIndex={0}
|
||||
className={clsx(className, styles.codeBlock, {
|
||||
[styles.codeBlockWithTitle]: codeBlockTitle,
|
||||
})}>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue