Skip to content

Commit eaf4964

Browse files
feat: imperative mode open/close delay
1 parent c19a861 commit eaf4964

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/components/Tooltip/Tooltip.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@ const Tooltip = ({
158158
}
159159
}, [show])
160160

161-
const handleShowTooltipDelayed = () => {
161+
const handleShowTooltipDelayed = (delay = delayShow) => {
162162
if (tooltipShowDelayTimerRef.current) {
163163
clearTimeout(tooltipShowDelayTimerRef.current)
164164
}
165165

166166
tooltipShowDelayTimerRef.current = setTimeout(() => {
167167
handleShow(true)
168-
}, delayShow)
168+
}, delay)
169169
}
170170

171171
const handleHideTooltipDelayed = (delay = delayHide) => {
@@ -672,10 +672,18 @@ const Tooltip = ({
672672
}
673673
}
674674
setImperativeOptions(options ?? null)
675-
handleShow(true)
675+
if (options?.delay) {
676+
handleShowTooltipDelayed(options.delay)
677+
} else {
678+
handleShow(true)
679+
}
676680
},
677-
close: () => {
678-
handleShow(false)
681+
close: (options) => {
682+
if (options?.delay) {
683+
handleHideTooltipDelayed(options.delay)
684+
} else {
685+
handleShow(false)
686+
}
679687
},
680688
activeAnchor,
681689
place: actualPlacement,

src/components/Tooltip/TooltipTypes.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,16 @@ export interface TooltipImperativeOpenOptions {
5454
position?: IPosition
5555
place?: PlacesType
5656
content?: ChildrenType
57+
delay?: number
58+
}
59+
60+
export interface TooltipImperativeCloseOptions {
61+
delay?: number
5762
}
5863

5964
export interface TooltipImperativeProps {
6065
open: (options?: TooltipImperativeOpenOptions) => void
61-
close: () => void
66+
close: (options?: TooltipImperativeCloseOptions) => void
6267
/**
6368
* @readonly
6469
*/

0 commit comments

Comments
 (0)