Skip to content

Commit 4157c6d

Browse files
feat: closeOnScroll and closeOnResize props
1 parent bb8bb76 commit 4157c6d

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

src/components/Tooltip/Tooltip.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const Tooltip = ({
2929
noArrow = false,
3030
clickable = false,
3131
closeOnEsc = false,
32+
closeOnScroll = false,
33+
closeOnResize = false,
3234
style: externalStyles,
3335
position,
3436
afterShow,
@@ -300,6 +302,13 @@ const Tooltip = ({
300302
elementRefs.add({ current: anchorById })
301303
}
302304

305+
if (closeOnScroll) {
306+
window.addEventListener('scroll', debouncedHandleHideTooltip)
307+
}
308+
if (closeOnResize) {
309+
window.addEventListener('resize', debouncedHandleHideTooltip)
310+
}
311+
303312
if (closeOnEsc) {
304313
window.addEventListener('keydown', handleEsc)
305314
}
@@ -344,6 +353,12 @@ const Tooltip = ({
344353
})
345354

346355
return () => {
356+
if (closeOnScroll) {
357+
window.removeEventListener('scroll', debouncedHandleHideTooltip)
358+
}
359+
if (closeOnResize) {
360+
window.removeEventListener('resize', debouncedHandleHideTooltip)
361+
}
347362
if (shouldOpenOnClick) {
348363
window.removeEventListener('click', handleClickOutsideAnchors)
349364
}

src/components/Tooltip/TooltipTypes.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export interface ITooltip {
6767
noArrow?: boolean
6868
clickable?: boolean
6969
closeOnEsc?: boolean
70+
closeOnScroll?: boolean
71+
closeOnResize?: boolean
7072
style?: CSSProperties
7173
position?: IPosition
7274
isOpen?: boolean

src/components/TooltipController/TooltipController.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const TooltipController = ({
3939
noArrow = false,
4040
clickable = false,
4141
closeOnEsc = false,
42+
closeOnScroll = false,
43+
closeOnResize = false,
4244
style,
4345
position,
4446
isOpen,
@@ -276,6 +278,8 @@ const TooltipController = ({
276278
noArrow,
277279
clickable,
278280
closeOnEsc,
281+
closeOnScroll,
282+
closeOnResize,
279283
style,
280284
position,
281285
isOpen,

src/components/TooltipController/TooltipControllerTypes.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export interface ITooltipController {
4646
noArrow?: boolean
4747
clickable?: boolean
4848
closeOnEsc?: boolean
49+
closeOnScroll?: boolean
50+
closeOnResize?: boolean
4951
style?: CSSProperties
5052
position?: IPosition
5153
isOpen?: boolean

0 commit comments

Comments
 (0)