|
1 | 1 | import { FloatingPortal, useMergeRefs } from "@floating-ui/react"; |
| 2 | +import classNames from "classnames"; |
2 | 3 | import { |
3 | 4 | cloneElement, |
4 | 5 | forwardRef, |
|
7 | 8 | type ReactNode, |
8 | 9 | type Ref, |
9 | 10 | } from "react"; |
10 | | -import { ZIndex } from "@web/common/constants/web.constants"; |
| 11 | +import { Z_INDEX_TOOLTIP, ZIndex } from "@web/common/constants/web.constants"; |
11 | 12 | import { useGridMaxZIndex } from "@web/common/hooks/useGridMaxZIndex"; |
12 | 13 | import { type TooltipOptions } from "./tooltip.types"; |
13 | 14 | import { TooltipContext, useTooltip, useTooltipContext } from "./useTooltip"; |
@@ -65,22 +66,24 @@ export const TooltipTrigger = forwardRef< |
65 | 66 | export const TooltipContent = forwardRef< |
66 | 67 | HTMLDivElement, |
67 | 68 | HTMLProps<HTMLDivElement> |
68 | | ->(function TooltipContent({ children, style, ...props }, propRef) { |
| 69 | +>(function TooltipContent({ children, className, style, ...props }, propRef) { |
69 | 70 | const context = useTooltipContext(); |
70 | 71 | const maxZIndex = useGridMaxZIndex(); |
71 | 72 | const ref = useMergeRefs([context.refs.setFloating, propRef]); |
72 | 73 |
|
73 | 74 | return ( |
74 | 75 | <FloatingPortal> |
75 | | - {context.open && ( |
| 76 | + {context.isMounted && ( |
76 | 77 | <div |
77 | 78 | ref={ref} |
| 79 | + className={classNames("c-tooltip", className)} |
78 | 80 | style={{ |
79 | 81 | left: context.x ?? 0, |
80 | 82 | position: context.strategy, |
81 | 83 | top: context.y ?? 0, |
82 | 84 | visibility: context.x == null ? "hidden" : "visible", |
83 | | - zIndex: maxZIndex + ZIndex.LAYER_3, |
| 85 | + zIndex: Math.max(maxZIndex + ZIndex.LAYER_3, Z_INDEX_TOOLTIP), |
| 86 | + ...context.transitionStyles, |
84 | 87 | ...style, |
85 | 88 | }} |
86 | 89 | {...context.getFloatingProps(props)} |
|
0 commit comments