@sanity/ui 2.8.2 → 2.8.3

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.2",
3
+ "version": "2.8.3",
4
4
  "keywords": [
5
5
  "sanity",
6
6
  "ui",
@@ -1,5 +1,14 @@
1
- import {Children, forwardRef, Fragment, isValidElement, useCallback, useMemo, useState} from 'react'
2
- import {useArrayProp, useClickOutside} from '../../hooks'
1
+ import {
2
+ Children,
3
+ forwardRef,
4
+ Fragment,
5
+ isValidElement,
6
+ useCallback,
7
+ useMemo,
8
+ useRef,
9
+ useState,
10
+ } from 'react'
11
+ import {useArrayProp, useClickOutsideEvent} from '../../hooks'
3
12
  import {Box, Popover, Stack, Text} from '../../primitives'
4
13
  import {ExpandButton, Root} from './breadcrumbs.styles'
5
14
 
@@ -22,13 +31,13 @@ export const Breadcrumbs = forwardRef(function Breadcrumbs(
22
31
  const {children, maxLength, separator, space: spaceRaw = 2, ...restProps} = props
23
32
  const space = useArrayProp(spaceRaw)
24
33
  const [open, setOpen] = useState(false)
25
- const [expandElement, setExpandElement] = useState<HTMLButtonElement | null>(null)
26
- const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
34
+ const expandElementRef = useRef<HTMLButtonElement | null>(null)
35
+ const popoverElementRef = useRef<HTMLDivElement | null>(null)
27
36
 
28
37
  const collapse = useCallback(() => setOpen(false), [])
29
38
  const expand = useCallback(() => setOpen(true), [])
30
39
 
31
- useClickOutside(collapse, [expandElement, popoverElement])
40
+ useClickOutsideEvent(collapse, () => [expandElementRef.current, popoverElementRef.current])
32
41
 
33
42
  const rawItems = useMemo(() => Children.toArray(children).filter(isValidElement), [children])
34
43
 
@@ -52,14 +61,14 @@ export const Breadcrumbs = forwardRef(function Breadcrumbs(
52
61
  open={open}
53
62
  placement="top"
54
63
  portal
55
- ref={setPopoverElement}
64
+ ref={popoverElementRef}
56
65
  >
57
66
  <ExpandButton
58
67
  fontSize={1}
59
68
  mode="bleed"
60
69
  onClick={open ? collapse : expand}
61
70
  padding={1}
62
- ref={setExpandElement}
71
+ ref={expandElementRef}
63
72
  selected={open}
64
73
  text="…"
65
74
  />