Skip to content

Commit

Permalink
fix the tooltip transition
Browse files Browse the repository at this point in the history
  • Loading branch information
binrysearch committed Sep 5, 2024
1 parent 5171c76 commit 4db5719
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/packages/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ export type TooltipProps = {
hintMode: boolean;
showStepNumbers: boolean;

transitionDuration?: number;

// auto-alignment properties
autoPosition: boolean;
positionPrecedence: TooltipPosition[];
Expand All @@ -314,6 +316,8 @@ export const Tooltip = (
hintMode = false,
showStepNumbers = false,

transitionDuration = 0,

// auto-alignment properties
autoPosition = true,
positionPrecedence = [],
Expand Down Expand Up @@ -398,12 +402,10 @@ export const Tooltip = (
]
);

// wait for the helper layer to be rendered before showing the tooltip
// this is to prevent the tooltip from flickering when the helper layer is transitioning
// the 300ms delay is coming from the helper layer transition duration
// apply the transition effect
setTimeout(() => {
opacity.val = 1;
}, 300);
}, transitionDuration);

return tooltip;
};
10 changes: 10 additions & 0 deletions src/packages/tour/components/TourRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export const TourRoot = ({ tour }: TourRootProps) => {
});

const opacity = van.state(0);
// render the tooltip immediately when the tour starts
// but we reset the transition duration to 300ms when the tooltip is rendered for the first time
let tooltipTransitionDuration = 0;

const root = div(
{
Expand Down Expand Up @@ -65,6 +68,8 @@ export const TourRoot = ({ tour }: TourRootProps) => {
targetElement: tour.getTargetElement(),
helperElementPadding: tour.getOption("helperElementPadding"),

transitionDuration: tooltipTransitionDuration,

positionPrecedence: tour.getOption("positionPrecedence"),
autoPosition: tour.getOption("autoPosition"),
showStepNumbers: tour.getOption("showStepNumbers"),
Expand Down Expand Up @@ -147,6 +152,11 @@ export const TourRoot = ({ tour }: TourRootProps) => {
})
: null;

// wait for the helper layer to be rendered before showing the tooltip
// this is to prevent the tooltip from flickering when the helper layer is transitioning
// the 300ms delay is coming from the helper layer transition duration
tooltipTransitionDuration = 300;

return div(
overlayLayer,
referenceLayer,
Expand Down

0 comments on commit 4db5719

Please sign in to comment.