@sanity/ui 2.6.5 → 2.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +5 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/core/primitives/tooltip/tooltip.tsx +7 -5
package/package.json
CHANGED
|
@@ -268,6 +268,9 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
268
268
|
[childProp?.props, handleIsOpenChange],
|
|
269
269
|
)
|
|
270
270
|
|
|
271
|
+
// Handle closing the tooltip when the mouse leaves the referenceElement
|
|
272
|
+
useCloseOnMouseLeave({handleIsOpenChange, referenceElement, showTooltip})
|
|
273
|
+
|
|
271
274
|
// Close when `disabled` changes to `true`
|
|
272
275
|
useEffect(() => {
|
|
273
276
|
if (disabled && showTooltip) handleIsOpenChange(false)
|
|
@@ -298,9 +301,6 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
298
301
|
}
|
|
299
302
|
}, [handleIsOpenChange, showTooltip])
|
|
300
303
|
|
|
301
|
-
// Handle closing the tooltip when the mouse leaves the referenceElement
|
|
302
|
-
useCloseOnMouseLeave({handleIsOpenChange, referenceElement, showTooltip})
|
|
303
|
-
|
|
304
304
|
// // Set the max width of the tooltip based on boundaries and portals
|
|
305
305
|
useLayoutEffect(() => {
|
|
306
306
|
// Get the maximum tooltip width (sans tooltip padding)
|
|
@@ -446,7 +446,7 @@ function useCloseOnMouseLeave({
|
|
|
446
446
|
// Since we don't want the `mouseevent` events to be attached and removed if the `referenceElement` is changed
|
|
447
447
|
// we use a "effect event" (https://19.react.dev/learn/separating-events-from-effects#reading-latest-props-and-state-with-effect-events)
|
|
448
448
|
// in order to always see the latest `referenceElement` value inside the event handler itself.
|
|
449
|
-
const onMouseMove = useEffectEvent((target: EventTarget | null) => {
|
|
449
|
+
const onMouseMove = useEffectEvent((target: EventTarget | null, teardown: () => void) => {
|
|
450
450
|
if (!referenceElement) return
|
|
451
451
|
|
|
452
452
|
const isHoveringReference =
|
|
@@ -454,6 +454,8 @@ function useCloseOnMouseLeave({
|
|
|
454
454
|
|
|
455
455
|
if (!isHoveringReference) {
|
|
456
456
|
handleIsOpenChange(false)
|
|
457
|
+
// Allow removing the event listener eagerly, to avoid race conditions
|
|
458
|
+
teardown()
|
|
457
459
|
}
|
|
458
460
|
})
|
|
459
461
|
|
|
@@ -464,7 +466,7 @@ function useCloseOnMouseLeave({
|
|
|
464
466
|
if (!showTooltip) return
|
|
465
467
|
|
|
466
468
|
const handleMouseMove = (event: MouseEvent) => {
|
|
467
|
-
onMouseMove(event.target)
|
|
469
|
+
onMouseMove(event.target, () => window.removeEventListener('mousemove', handleMouseMove))
|
|
468
470
|
}
|
|
469
471
|
|
|
470
472
|
window.addEventListener('mousemove', handleMouseMove)
|