Fixed pointer issue with Link elements

This commit is contained in:
DrMint 2022-11-01 03:43:36 +01:00
parent 16db6a9a39
commit f4ff30e279
1 changed files with 5 additions and 5 deletions

View File

@ -1,5 +1,5 @@
import router from "next/router"; import router from "next/router";
import { PointerEventHandler, useState } from "react"; import { MouseEventHandler, useState } from "react";
import { isDefined } from "helpers/others"; import { isDefined } from "helpers/others";
interface Props { interface Props {
@ -8,7 +8,7 @@ interface Props {
allowNewTab?: boolean; allowNewTab?: boolean;
alwaysNewTab?: boolean; alwaysNewTab?: boolean;
children: React.ReactNode; children: React.ReactNode;
onClick?: PointerEventHandler<HTMLDivElement>; onClick?: MouseEventHandler<HTMLDivElement>;
onFocusChanged?: (isFocused: boolean) => void; onFocusChanged?: (isFocused: boolean) => void;
disabled?: boolean; disabled?: boolean;
} }
@ -28,19 +28,19 @@ export const Link = ({
return ( return (
<div <div
className={className} className={className}
onPointerLeave={() => { onMouseLeave={() => {
setIsValidClick(false); setIsValidClick(false);
onFocusChanged?.(false); onFocusChanged?.(false);
}} }}
onContextMenu={(event) => event.preventDefault()} onContextMenu={(event) => event.preventDefault()}
onPointerDown={(event) => { onMouseDown={(event) => {
if (!disabled) { if (!disabled) {
event.preventDefault(); event.preventDefault();
onFocusChanged?.(true); onFocusChanged?.(true);
setIsValidClick(true); setIsValidClick(true);
} }
}} }}
onPointerUp={(event) => { onMouseUp={(event) => {
onFocusChanged?.(false); onFocusChanged?.(false);
if (!disabled) { if (!disabled) {
if (isDefined(onClick)) { if (isDefined(onClick)) {