fix: remove hover effect on touch devices

This commit is contained in:
thecodrr
2022-07-06 11:11:31 +05:00
parent 0caf41b8b7
commit dda66bcf95
3 changed files with 13 additions and 6 deletions

View File

@@ -4,6 +4,8 @@ import { Button as RebassButton, ButtonProps } from "rebass";
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
(props: ButtonProps, forwardedRef) => {
const { sx, ...buttonProps } = props;
const hoverBg = (sx as any)?.[":hover"]?.["bg"] || "hover";
const buttonRef = useRef<HTMLButtonElement>();
useEffect(() => {
@@ -27,7 +29,12 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
return (
<RebassButton
{...props}
{...buttonProps}
sx={{
...sx,
":hover": { bg: ["transparent", hoverBg] },
":active": { bg: hoverBg },
}}
ref={(ref) => {
buttonRef.current = ref;
if (typeof forwardedRef === "function") forwardedRef(ref);

View File

@@ -26,15 +26,16 @@ function _SplitButton(props: PropsWithChildren<SplitButtonProps>) {
sx={{
borderRadius: "default",
bg: toggled ? "hover" : "transparent",
":hover": { bg: "hover" },
":hover": { bg: [toggled ? "hover" : "transparent", "hover"] },
":active": { bg: toggled ? "hover" : "transparent" },
}}
>
<ToolButton {...toolButtonProps} toggled={toggled} />
<ToolButton {...toolButtonProps} toggled={false} />
<Button
sx={{
p: 0,
m: 0,
bg: toggled ? "hover" : "transparent",
bg: "transparent",
":hover": { bg: "hover" },
":last-of-type": {
mr: 0,

View File

@@ -42,8 +42,7 @@ export const ToolButton = React.memo(
m: 0,
bg: toggled ? "hover" : "transparent",
mr: variant === "small" ? 0 : 1,
":hover": { bg: ["transparent", "hover"] },
":active": { bg: "hover" },
":hover": { bg: "hover" },
":last-of-type": {
mr: 0,
},