@sanity/ui 2.3.6-canary.3 → 2.3.6-canary.5

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.3.6-canary.3",
3
+ "version": "2.3.6-canary.5",
4
4
  "keywords": [
5
5
  "sanity",
6
6
  "ui",
@@ -11,6 +11,7 @@ import {useMenuController} from './useMenuController'
11
11
  * @public
12
12
  */
13
13
  export interface MenuProps extends ResponsivePaddingProps {
14
+ 'aria-labelledby'?: string
14
15
  /**
15
16
  * @deprecated Use `shouldFocus="first"` instead.
16
17
  */
@@ -20,6 +21,7 @@ export interface MenuProps extends ResponsivePaddingProps {
20
21
  */
21
22
  focusLast?: boolean
22
23
  onClickOutside?: (event: MouseEvent) => void
24
+ onBlurCapture?: (event: React.FocusEvent<HTMLButtonElement>) => void
23
25
  onEscape?: () => void
24
26
  onItemClick?: () => void
25
27
  onItemSelect?: (index: number) => void
@@ -203,8 +203,9 @@ export const MenuButton = forwardRef(function MenuButton(
203
203
  }
204
204
  }, [])
205
205
 
206
- const menuProps: MenuProps = useMemo(
207
- () => ({
206
+ const menu =
207
+ menuProp &&
208
+ cloneElement<MenuProps>(menuProp, {
208
209
  'aria-labelledby': id,
209
210
  onBlurCapture: handleBlur,
210
211
  onClickOutside: handleMenuClickOutside,
@@ -213,22 +214,8 @@ export const MenuButton = forwardRef(function MenuButton(
213
214
  originElement: buttonElement,
214
215
  registerElement,
215
216
  shouldFocus,
216
- }),
217
- [
218
- buttonElement,
219
- handleMenuClickOutside,
220
- handleMenuEscape,
221
- handleItemClick,
222
- id,
223
- handleBlur,
224
- registerElement,
225
- shouldFocus,
226
- ],
227
- )
228
-
229
- const menu = menuProp && cloneElement(menuProp, menuProps)
217
+ })
230
218
 
231
- const ref = useRef<HTMLButtonElement | null>(null)
232
219
  const button = useMemo(
233
220
  () =>
234
221
  buttonProp &&
@@ -240,7 +227,7 @@ export const MenuButton = forwardRef(function MenuButton(
240
227
  onMouseDown: handleMouseDown,
241
228
  'aria-haspopup': true,
242
229
  'aria-expanded': open,
243
- ref: ref,
230
+ ref: setButtonElement,
244
231
  selected: buttonProp.props.selected ?? open,
245
232
  }),
246
233
  [buttonProp, handleButtonClick, handleButtonKeyDown, handleMouseDown, id, open],
@@ -249,19 +236,10 @@ export const MenuButton = forwardRef(function MenuButton(
249
236
  // Forward button ref to parent
250
237
  useImperativeHandle<HTMLButtonElement | null, HTMLButtonElement | null>(
251
238
  forwardedRef,
252
- () => ref.current,
239
+ () => buttonElement,
240
+ [buttonElement],
253
241
  )
254
242
 
255
- // If there's a button then we need to set the reference element to the cloned button ref
256
- // and if button changes we make sure to update or remove the reference element.
257
- useEffect(() => {
258
- if (!button) return undefined
259
-
260
- setButtonElement(ref.current)
261
-
262
- return () => setButtonElement(null)
263
- }, [button])
264
-
265
243
  const popoverProps: MenuButtonProps['popover'] = useMemo(
266
244
  () => ({
267
245
  boundaryElement: deprecated_boundaryElement,
@@ -285,8 +263,15 @@ export const MenuButton = forwardRef(function MenuButton(
285
263
  )
286
264
 
287
265
  return (
288
- <Popover data-ui="MenuButton__popover" {...popoverProps} content={menu} open={open}>
289
- {button || <></>}
290
- </Popover>
266
+ <>
267
+ <Popover
268
+ data-ui="MenuButton__popover"
269
+ referenceElement={buttonElement}
270
+ {...popoverProps}
271
+ content={menu}
272
+ open={open}
273
+ />
274
+ {button}
275
+ </>
291
276
  )
292
277
  })
@@ -27,8 +27,8 @@ export function ThemeProvider(props: ThemeProviderProps): React.ReactElement {
27
27
  const {children} = props
28
28
  const parentTheme = useContext(ThemeContext)
29
29
  const scheme = props.scheme ?? (parentTheme?.scheme || 'light')
30
- const rootTheme = parentTheme?.theme || null
31
- const tone = parentTheme?.tone || 'default'
30
+ const rootTheme = props.theme ?? (parentTheme?.theme || null)
31
+ const tone = props.tone ?? (parentTheme?.tone || 'default')
32
32
 
33
33
  const themeContext: ThemeContextValue | null = useMemo(() => {
34
34
  if (!rootTheme) return null