@sanity/ui 2.8.3 → 2.8.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "2.8.3",
3
+ "version": "2.8.4",
4
4
  "keywords": [
5
5
  "sanity",
6
6
  "ui",
@@ -1,6 +1,6 @@
1
1
  import {CloseIcon} from '@sanity/icons'
2
2
  import {ThemeColorSchemeKey} from '@sanity/ui/theme'
3
- import {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react'
3
+ import {forwardRef, useCallback, useEffect, useImperativeHandle, useRef} from 'react'
4
4
  import {styled} from 'styled-components'
5
5
  import {
6
6
  containsOrEqualsElement,
@@ -8,7 +8,12 @@ import {
8
8
  focusLastDescendant,
9
9
  isHTMLElement,
10
10
  } from '../../helpers'
11
- import {useArrayProp, useClickOutside, useGlobalKeyDown, usePrefersReducedMotion} from '../../hooks'
11
+ import {
12
+ useArrayProp,
13
+ useClickOutsideEvent,
14
+ useGlobalKeyDown,
15
+ usePrefersReducedMotion,
16
+ } from '../../hooks'
12
17
  import {Box, Button, Card, Container, Flex, Text} from '../../primitives'
13
18
  import {ResponsivePaddingProps, ResponsiveWidthProps} from '../../primitives/types'
14
19
  import {responsivePaddingStyle, ResponsivePaddingStyleProps} from '../../styles/internal'
@@ -170,7 +175,6 @@ const DialogCard = forwardRef(function DialogCard(
170
175
  const shadow = useArrayProp(shadowProp)
171
176
  const width = useArrayProp(widthProp)
172
177
  const ref = useRef<HTMLDivElement | null>(null)
173
- const [rootElement, setRootElement] = useState<HTMLDivElement | null>(null)
174
178
  const contentRef = useRef<HTMLDivElement | null>(null)
175
179
  const layer = useLayer()
176
180
  const {isTopLayer} = layer
@@ -215,11 +219,10 @@ const DialogCard = forwardRef(function DialogCard(
215
219
  ),
216
220
  )
217
221
 
218
- useClickOutside(
219
- useCallback(
220
- (event) => {
221
- if (!isTopLayer || !onClickOutside) return
222
-
222
+ useClickOutsideEvent(
223
+ isTopLayer &&
224
+ onClickOutside &&
225
+ ((event) => {
223
226
  const target = event.target as Node | null
224
227
 
225
228
  if (target && !isTargetWithinScope(boundaryElement, portalElement, target)) {
@@ -228,20 +231,13 @@ const DialogCard = forwardRef(function DialogCard(
228
231
  }
229
232
 
230
233
  onClickOutside()
231
- },
232
- [boundaryElement, isTopLayer, onClickOutside, portalElement],
233
- ),
234
- [rootElement],
234
+ }),
235
+ () => [ref.current],
235
236
  )
236
237
 
237
- const setRef = useCallback((el: HTMLDivElement | null) => {
238
- setRootElement(el)
239
- ref.current = el
240
- }, [])
241
-
242
238
  return (
243
239
  <DialogContainer data-ui="DialogCard" width={width}>
244
- <DialogCardRoot radius={radius} ref={setRef} scheme={scheme} shadow={shadow}>
240
+ <DialogCardRoot radius={radius} ref={ref} scheme={scheme} shadow={shadow}>
245
241
  <DialogLayout direction="column">
246
242
  {showHeader && (
247
243
  <DialogHeader>