Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tooltip position after scroll #230

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/layers/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC, useState, useRef, useEffect, ReactNode } from 'react';
import { ConnectedOverlay, TriggerTypes } from '@/utils/Overlay';
import { Placement, ReferenceObject } from '@/utils/Position';
import { Modifiers, Placement, ReferenceObject } from '@/utils/Position';
import { motion } from 'framer-motion';
import { twMerge } from 'tailwind-merge';
import { useTooltipState } from './useTooltipState';
Expand Down Expand Up @@ -56,7 +56,7 @@ export interface TooltipProps {
/**
* floating-ui modifiers.
*/
modifiers?: any;
modifiers?: Modifiers;

/**
* External setter for visibility.
Expand Down
4 changes: 2 additions & 2 deletions src/utils/Overlay/ConnectedOverlay/ConnectedOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, {
useMemo
} from 'react';
import { TriggerTypes, OverlayTrigger } from '@/utils/Overlay/OverlayTrigger';
import { Placement, ReferenceProp } from '@/utils/Position';
import { Modifiers, Placement, ReferenceProp } from '@/utils/Position';
import { AnimatePresence } from 'framer-motion';
import { OverlayContext } from '@/utils/Overlay/OverlayContext';
import {
Expand Down Expand Up @@ -93,7 +93,7 @@ export interface ConnectedOverlayProps {
/**
* Position modifiers.
*/
modifiers?: any;
modifiers?: Modifiers;

/**
* Overlay should follow cursor or not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, {
LegacyRef
} from 'react';
import { useExitListener } from '@/utils/ExitListener';
import { Placement, usePosition } from '@/utils/Position';
import { Modifiers, Placement, usePosition } from '@/utils/Position';
import { OverlayPortal, portals } from '@/utils/Overlay/OverlayPortal';
import { useId } from '@/utils/useId';

Expand All @@ -21,7 +21,7 @@ export interface ConnectedOverlayContentProps {
/**
* Modifiers to adjust the behavior of the overlay content.
*/
modifiers?: any;
modifiers?: Modifiers;

/**
* If true, the overlay content will follow the cursor.
Expand Down
18 changes: 9 additions & 9 deletions src/utils/Position/usePosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const usePosition = ({
});

useEffect(() => {
if (isVirtualElement && reference) {
if (isVirtualElement && reference && !followCursor) {
const refObject = reference as ReferenceObject;
refs.setPositionReference({
getBoundingClientRect() {
Expand All @@ -79,22 +79,22 @@ export const usePosition = ({
}
});
}
}, [reference, refs, isVirtualElement]);
}, [reference, refs, isVirtualElement, followCursor]);

const onMouseMove = useCallback(
({ pageX, pageY }: MouseEvent) => {
({ clientX, clientY }: MouseEvent) => {
// Virtual reference object for cursor position.
refs.setPositionReference({
getBoundingClientRect() {
return {
width: 0,
height: 0,
x: pageX,
y: pageY,
left: pageX,
top: pageY,
right: pageX,
bottom: pageY
x: clientX,
y: clientY,
left: clientX,
top: clientY,
right: clientX,
bottom: clientY
};
}
});
Expand Down
Loading