Skip to content

Commit a8f5443

Browse files
feat: imperativeModeOnly prop
1 parent bb09708 commit a8f5443

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

src/App.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ function App() {
103103
ref={tooltipRef}
104104
anchorSelect="section[id='section-anchor-select'] > p > button"
105105
place="bottom"
106-
openEvents={{ click: true }}
107-
closeEvents={{ click: true }}
108-
globalCloseEvents={{ clickOutsideAnchor: true }}
106+
imperativeModeOnly
109107
>
110108
Tooltip content
111109
</Tooltip>

src/components/Tooltip/Tooltip.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const Tooltip = ({
4646
openEvents,
4747
closeEvents,
4848
globalCloseEvents,
49+
imperativeModeOnly,
4950
style: externalStyles,
5051
position,
5152
afterShow,
@@ -111,6 +112,8 @@ const Tooltip = ({
111112
mouseleave: true,
112113
blur: true,
113114
click: false,
115+
dblclick: false,
116+
mouseup: false,
114117
}
115118
if (!closeEvents && shouldOpenOnClick) {
116119
Object.assign(actualCloseEvents, {
@@ -127,6 +130,29 @@ const Tooltip = ({
127130
clickOutsideAnchor: hasClickEvent || false,
128131
}
129132

133+
if (imperativeModeOnly) {
134+
Object.assign(actualOpenEvents, {
135+
mouseenter: false,
136+
focus: false,
137+
click: false,
138+
dblclick: false,
139+
mousedown: false,
140+
})
141+
Object.assign(actualCloseEvents, {
142+
mouseleave: false,
143+
blur: false,
144+
click: false,
145+
dblclick: false,
146+
mouseup: false,
147+
})
148+
Object.assign(actualGlobalCloseEvents, {
149+
escape: false,
150+
scroll: false,
151+
resize: false,
152+
clickOutsideAnchor: false,
153+
})
154+
}
155+
130156
/**
131157
* useLayoutEffect runs before useEffect,
132158
* but should be used carefully because of caveats

src/components/Tooltip/TooltipTypes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export interface ITooltip {
141141
openEvents?: AnchorOpenEvents
142142
closeEvents?: AnchorCloseEvents
143143
globalCloseEvents?: GlobalCloseEvents
144+
imperativeModeOnly?: boolean
144145
style?: CSSProperties
145146
position?: IPosition
146147
isOpen?: boolean

src/components/TooltipController/TooltipController.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const TooltipController = React.forwardRef<TooltipImperativeProps, ITooltipContr
4747
openEvents,
4848
closeEvents,
4949
globalCloseEvents,
50+
imperativeModeOnly = false,
5051
style,
5152
position,
5253
isOpen,
@@ -342,6 +343,7 @@ const TooltipController = React.forwardRef<TooltipImperativeProps, ITooltipContr
342343
openEvents,
343344
closeEvents,
344345
globalCloseEvents,
346+
imperativeModeOnly,
345347
style,
346348
position,
347349
isOpen,

src/components/TooltipController/TooltipControllerTypes.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export interface ITooltipController {
7272
* @description The global events listened to close the tooltip.
7373
*/
7474
globalCloseEvents?: GlobalCloseEvents
75+
/**
76+
* @description Used to disable default tooltip behavior.
77+
* Overrides `openEvents`, `closeEvents`, and `globalCloseEvents`.
78+
*/
79+
imperativeModeOnly?: boolean
7580
style?: CSSProperties
7681
position?: IPosition
7782
isOpen?: boolean

0 commit comments

Comments
 (0)