@zag-js/interact-outside
Advanced tools
Comparing version 0.79.2 to 0.79.3
@@ -83,8 +83,22 @@ 'use strict'; | ||
} | ||
function isEventWithinScrollbar(event, target) { | ||
if (!target || !isPointerEvent(event)) return false; | ||
const isScrollableY = target.scrollHeight > target.clientHeight; | ||
const onScrollbarY = isScrollableY && event.clientX > target.clientWidth; | ||
const isScrollableX = target.scrollWidth > target.clientWidth; | ||
const onScrollbarX = isScrollableX && event.clientY > target.clientHeight; | ||
function isPointInRect(rect, point) { | ||
return rect.y <= point.y && point.y <= rect.y + rect.height && rect.x <= point.x && point.x <= rect.x + rect.width; | ||
} | ||
function isEventWithinScrollbar(event, ancestor) { | ||
if (!ancestor || !isPointerEvent(event)) return false; | ||
const isScrollableY = ancestor.scrollHeight > ancestor.clientHeight; | ||
const onScrollbarY = isScrollableY && event.clientX > ancestor.offsetLeft + ancestor.clientWidth; | ||
const isScrollableX = ancestor.scrollWidth > ancestor.clientWidth; | ||
const onScrollbarX = isScrollableX && event.clientY > ancestor.offsetTop + ancestor.clientHeight; | ||
const rect = { | ||
x: ancestor.offsetLeft, | ||
y: ancestor.offsetTop, | ||
width: ancestor.clientWidth + (isScrollableY ? 16 : 0), | ||
height: ancestor.clientHeight + (isScrollableX ? 16 : 0) | ||
}; | ||
const point = { | ||
x: event.clientX, | ||
y: event.clientY | ||
}; | ||
if (!isPointInRect(rect, point)) return false; | ||
return onScrollbarY || onScrollbarX; | ||
@@ -105,5 +119,9 @@ } | ||
if (isEventPointWithin(node, event)) return false; | ||
if (isEventWithinScrollbar(event, target)) return false; | ||
const scrollParent = domQuery.getNearestOverflowAncestor(node); | ||
if (isEventWithinScrollbar(event, scrollParent)) return false; | ||
const triggerEl = doc.querySelector(`[aria-controls="${node.id}"]`); | ||
if (triggerEl) { | ||
const triggerAncestor = domQuery.getNearestOverflowAncestor(triggerEl); | ||
if (isEventWithinScrollbar(event, triggerAncestor)) return false; | ||
} | ||
const nodeAncestor = domQuery.getNearestOverflowAncestor(node); | ||
if (isEventWithinScrollbar(event, nodeAncestor)) return false; | ||
return !exclude?.(target); | ||
@@ -110,0 +128,0 @@ } |
{ | ||
"name": "@zag-js/interact-outside", | ||
"version": "0.79.2", | ||
"version": "0.79.3", | ||
"description": "Track interactions or focus outside an element", | ||
@@ -19,5 +19,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/dom-query": "0.79.2", | ||
"@zag-js/dom-event": "0.79.2", | ||
"@zag-js/utils": "0.79.2" | ||
"@zag-js/dom-query": "0.79.3", | ||
"@zag-js/dom-event": "0.79.3", | ||
"@zag-js/utils": "0.79.3" | ||
}, | ||
@@ -24,0 +24,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20226
433
+ Added@zag-js/dom-event@0.79.3(transitive)
+ Added@zag-js/dom-query@0.79.3(transitive)
+ Added@zag-js/text-selection@0.79.3(transitive)
+ Added@zag-js/types@0.79.3(transitive)
+ Added@zag-js/utils@0.79.3(transitive)
- Removed@zag-js/dom-event@0.79.2(transitive)
- Removed@zag-js/dom-query@0.79.2(transitive)
- Removed@zag-js/text-selection@0.79.2(transitive)
- Removed@zag-js/types@0.79.2(transitive)
- Removed@zag-js/utils@0.79.2(transitive)
Updated@zag-js/dom-event@0.79.3
Updated@zag-js/dom-query@0.79.3
Updated@zag-js/utils@0.79.3