InfoPanel: make snippets keyboard-navigable and autoselected
Code snippets can now be navigated to be keyboard. Additionally, focusing this way or by single-clicking will select the entire snippet contents by default, then after a 50ms delay, allow for normal text selection. This is a better experience for copying, especially on mobile.
This commit is contained in:
@@ -87,10 +87,27 @@
|
|||||||
.snippet {
|
.snippet {
|
||||||
margin-bottom: 24px;
|
margin-bottom: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.snippet pre {
|
.snippet pre {
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
color: black;
|
color: black;
|
||||||
|
user-select: all;
|
||||||
|
-moz-user-select: all;
|
||||||
|
-webkit-user-select: all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.snippet pre:focus {
|
||||||
|
animation: select 50ms step-end forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes select {
|
||||||
|
to {
|
||||||
|
user-select: text;
|
||||||
|
-moz-user-select: text;
|
||||||
|
-webkit-user-select: text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.snippet button {
|
.snippet button {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ const InfoPanel: React.FC<InfoPanelProps> = (props) => {
|
|||||||
<div className="icon-usage">
|
<div className="icon-usage">
|
||||||
<div className="snippet">
|
<div className="snippet">
|
||||||
HTML/CSS
|
HTML/CSS
|
||||||
<pre>
|
<pre tabIndex={0}>
|
||||||
{snippets.html}
|
{snippets.html}
|
||||||
<button
|
<button
|
||||||
title="Copy snippet"
|
title="Copy snippet"
|
||||||
@@ -117,7 +117,7 @@ const InfoPanel: React.FC<InfoPanelProps> = (props) => {
|
|||||||
</div>
|
</div>
|
||||||
<div className="snippet">
|
<div className="snippet">
|
||||||
React
|
React
|
||||||
<pre>
|
<pre tabIndex={0}>
|
||||||
{snippets.react}
|
{snippets.react}
|
||||||
<button
|
<button
|
||||||
title="Copy snippet"
|
title="Copy snippet"
|
||||||
@@ -154,10 +154,12 @@ const InfoPanel: React.FC<InfoPanelProps> = (props) => {
|
|||||||
</div>
|
</div>
|
||||||
<X
|
<X
|
||||||
className="close-icon"
|
className="close-icon"
|
||||||
|
tabIndex={0}
|
||||||
color="currentColor"
|
color="currentColor"
|
||||||
size={32}
|
size={32}
|
||||||
weight="fill"
|
weight="fill"
|
||||||
onClick={() => setOpen(false)}
|
onClick={() => setOpen(false)}
|
||||||
|
onKeyDown={(e) => {e.key === "Enter" && setOpen(false)}}
|
||||||
/>
|
/>
|
||||||
</motion.section>
|
</motion.section>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user