Revert "Fix keyboard shortcut (#587)" (#617)

This reverts commit cc3d71f13c0604406eda838344d99866dd94df39.
This commit is contained in:
David Luzar 2020-01-30 10:40:49 +01:00 committed by GitHub
parent cc3d71f13c
commit 023400c3cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
import "./ToolIcon.scss"; import "./ToolIcon.scss";
import React, { useEffect } from "react"; import React from "react";
type ToolIconSize = "s" | "m"; type ToolIconSize = "s" | "m";
@ -30,25 +30,10 @@ export const ToolButton = React.forwardRef(function(
props: ToolButtonProps, props: ToolButtonProps,
ref, ref,
) { ) {
const innerRef = React.useRef<HTMLInputElement | HTMLButtonElement | null>( const innerRef = React.useRef(null);
null,
);
React.useImperativeHandle(ref, () => innerRef.current); React.useImperativeHandle(ref, () => innerRef.current);
const sizeCn = `ToolIcon_size_${props.size || DEFAULT_SIZE}`; const sizeCn = `ToolIcon_size_${props.size || DEFAULT_SIZE}`;
const prevChecked = React.useRef<boolean>(
"checked" in props && props.checked,
);
useEffect(() => {
if (props.type !== "button") {
if (props.checked && !prevChecked.current && innerRef.current) {
innerRef.current.focus();
}
prevChecked.current = props.checked;
}
});
if (props.type === "button") if (props.type === "button")
return ( return (
<button <button
@ -57,7 +42,7 @@ export const ToolButton = React.forwardRef(function(
aria-label={props["aria-label"]} aria-label={props["aria-label"]}
type="button" type="button"
onClick={props.onClick} onClick={props.onClick}
ref={node => (innerRef.current = node)} ref={innerRef}
> >
<div className="ToolIcon__icon" aria-hidden="true"> <div className="ToolIcon__icon" aria-hidden="true">
{props.icon || props.label} {props.icon || props.label}
@ -76,7 +61,7 @@ export const ToolButton = React.forwardRef(function(
id={props.id} id={props.id}
onChange={props.onChange} onChange={props.onChange}
checked={props.checked} checked={props.checked}
ref={node => (innerRef.current = node)} ref={innerRef}
/> />
<div className="ToolIcon__icon">{props.icon}</div> <div className="ToolIcon__icon">{props.icon}</div>
</label> </label>