Skip to content

Commit

Permalink
add safe polygon on hover
Browse files Browse the repository at this point in the history
  • Loading branch information
andreymikhadyuk committed Dec 19, 2023
1 parent a055b53 commit 4c2ee15
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const LinkedItemMark: FC<LinkedItemMarkProps> = (props) => {
open={isOpen}
onOpenChange={setIsOpen}
placement={isTabletView ? "bottom-start" : "right"}
shouldOpenOnHover={!isTabletView}
>
<TooltipTrigger onClick={toggleTooltip} asChild>
<ButtonIcon>
Expand Down
7 changes: 6 additions & 1 deletion src/shared/ui-kit/Tooltip/hooks/useTooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
autoUpdate,
offset,
flip,
safePolygon,
shift,
arrow,
useHover,
Expand All @@ -20,9 +21,12 @@ export const useTooltip = (options: TooltipOptions = {}) => {
placement = "top",
open: controlledOpen,
onOpenChange: setControlledOpen,
shouldOpenOnHover = false,
} = options;
const [uncontrolledOpen, setUncontrolledOpen] = useState(initialOpen);
const arrowRef = useRef<HTMLDivElement>(null);
const shouldEnableHover =
shouldOpenOnHover ?? typeof controlledOpen === "undefined";

const open = controlledOpen ?? uncontrolledOpen;
const setOpen = setControlledOpen ?? setUncontrolledOpen;
Expand All @@ -46,7 +50,8 @@ export const useTooltip = (options: TooltipOptions = {}) => {

const hover = useHover(context, {
move: false,
enabled: typeof controlledOpen === "undefined",
enabled: shouldEnableHover,
handleClose: shouldEnableHover ? safePolygon() : null,
});
const focus = useFocus(context, {
enabled: typeof controlledOpen === "undefined",
Expand Down
1 change: 1 addition & 0 deletions src/shared/ui-kit/Tooltip/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface TooltipOptions {
placement?: Placement;
open?: boolean;
onOpenChange?: (open: boolean) => void;
shouldOpenOnHover?: boolean;
}

0 comments on commit 4c2ee15

Please sign in to comment.