@sanity/ui 2.7.1-canary.1 → 2.8.0

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.js CHANGED
@@ -128,8 +128,13 @@ function useArrayProp(val, defaultVal) {
128
128
  }
129
129
  function useClickOutside(listener, elementsArg = EMPTY_ARRAY, boundaryElement) {
130
130
  const [legacyElement, setLegacyElement] = react.useState(null), onEvent = useEffectEvent.useEffectEvent((evt) => {
131
+ if (!listener)
132
+ return;
131
133
  const target = evt.target;
132
- if (!(target instanceof Node) || boundaryElement && !boundaryElement.contains(target))
134
+ if (!(target instanceof Node))
135
+ return;
136
+ const resolvedBoundaryElement = typeof boundaryElement == "function" ? boundaryElement() : boundaryElement;
137
+ if (resolvedBoundaryElement && !resolvedBoundaryElement.contains(target))
133
138
  return;
134
139
  const elements = (Array.isArray(elementsArg) ? [legacyElement, ...elementsArg] : elementsArg()).flat();
135
140
  for (const el of elements)
@@ -140,8 +145,8 @@ function useClickOutside(listener, elementsArg = EMPTY_ARRAY, boundaryElement) {
140
145
  if (react.useEffect(() => {
141
146
  if (!hasListener) return;
142
147
  const handleEvent = (evt) => onEvent(evt);
143
- return document.addEventListener("mousedown", handleEvent), document.addEventListener("touchstart", handleEvent), () => {
144
- document.removeEventListener("mousedown", handleEvent), document.removeEventListener("touchstart", handleEvent);
148
+ return document.addEventListener("mousedown", handleEvent), () => {
149
+ document.removeEventListener("mousedown", handleEvent);
145
150
  };
146
151
  }, [hasListener, onEvent]), Array.isArray(elementsArg))
147
152
  return setLegacyElement;
@@ -5099,14 +5104,11 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
5099
5104
  [boundaryElement, isTopLayer, onClose, portalElement]
5100
5105
  )
5101
5106
  ), useClickOutside(
5102
- react.useCallback(
5103
- (event) => {
5104
- if (!isTopLayer || !onClickOutside) return;
5105
- const target = event.target;
5106
- target && !isTargetWithinScope(boundaryElement, portalElement, target) || onClickOutside();
5107
- },
5108
- [boundaryElement, isTopLayer, onClickOutside, portalElement]
5109
- ),
5107
+ (event) => {
5108
+ if (!isTopLayer || !onClickOutside) return;
5109
+ const target = event.target;
5110
+ target && !isTargetWithinScope(boundaryElement, portalElement, target) || onClickOutside();
5111
+ },
5110
5112
  [rootElement]
5111
5113
  );
5112
5114
  const setRef = react.useCallback((el) => {
@@ -5443,13 +5445,7 @@ const Root$5 = styledComponents.styled(Box)`
5443
5445
  );
5444
5446
  react.useEffect(() => {
5445
5447
  onItemSelect && onItemSelect(activeIndex);
5446
- }, [activeIndex, onItemSelect]), useClickOutside(
5447
- react.useCallback(
5448
- (event) => isTopLayer && onClickOutside && onClickOutside(event),
5449
- [isTopLayer, onClickOutside]
5450
- ),
5451
- [rootElement]
5452
- ), useGlobalKeyDown(
5448
+ }, [activeIndex, onItemSelect]), useClickOutside((event) => isTopLayer && onClickOutside && onClickOutside(event), [rootElement]), useGlobalKeyDown(
5453
5449
  react.useCallback(
5454
5450
  (event) => {
5455
5451
  isTopLayer && event.key === "Escape" && (event.stopPropagation(), onEscape && onEscape());