message: refactor: cleanup document in use-menu hook
diff: @@ -25,7 +25,9 @@ import {
  focus,
  getNextIndex,
  getNextItemFromSearch,
  + getOwnerDocument,
  getPrevIndex,
  + isActiveElement,
  isArray,
  isString,
  normalizeEventKey,
  @@ -158,13 +160,14 @@ export function useMenu(props: UseMenuProps = {}) {
  }, [onOpen, setFocusedIndex, domContext.descendants])
  const refocus = React.useCallback(() => {
  - const hasFocusWithin = menuRef.current?.contains(document.activeElement)
  + const doc = getOwnerDocument(menuRef.current)
  + const hasFocusWithin = menuRef.current?.contains(doc.activeElement)
  const shouldRefocus = isOpen && !hasFocusWithin
  if (!shouldRefocus) return
  const el = domContext.descendants[focusedIndex]?.element
  - el?.focus({ preventScroll: true })
  + focus(el)
  }, [isOpen, focusedIndex, domContext.descendants])
  return {
  @@ -251,7 +254,7 @@ export function useMenuButton(
  [openAndFocusFirstItem, openAndFocusLastItem],
  )
  - const buttonProps = {
  + return {
  ...props,
  ref: mergeRefs(menu.buttonRef, externalRef, popper.referenceRef),
  id: menu.buttonId,
  @@ -262,8 +265,6 @@ export function useMenuButton(
  onClick: callAllHandlers(props.onClick, onClick),
  onKeyDown: callAllHandlers(props.onKeyDown, onKeyDown),
  }
  -
  - return buttonProps
  }
  /**
  @@ -404,7 +405,7 @@ export function useMenuItem(
  onClick: onClickProp,
  isDisabled,
  isFocusable,
  - closeOnSelect: menuItemCloseOnSelect,
  + closeOnSelect,
  ...htmlProps
  } = props
  @@ -437,7 +438,6 @@ export function useMenuItem(
  (event) => {
  onMouseEnterProp?.(event)
  if (isDisabled) return
  -
  setFocusedIndex(index)
  },
  [setFocusedIndex, index, isDisabled, onMouseEnterProp],
  @@ -446,7 +446,7 @@ export function useMenuItem(
  const onMouseMove = React.useCallback(
  (event) => {
  onMouseMoveProp?.(event)
  - if (document.activeElement !== ref.current) {
  + if (ref.current && !isActiveElement(ref.current)) {
  onMouseEnter(event)
  }
  },
  @@ -457,7 +457,6 @@ export function useMenuItem(
  (event) => {
  onMouseLeaveProp?.(event)
  if (isDisabled) return
  -
  setFocusedIndex(-1)
  },
  [setFocusedIndex, isDisabled, onMouseLeaveProp],
  @@ -470,11 +469,11 @@ export function useMenuItem(
  * Close menu and parent menus, allowing the MenuItem
  * to override its parent menu's `closeOnSelect` prop.
  */
  - if (menuItemCloseOnSelect ?? menuCloseOnSelect) {
  + if (closeOnSelect ?? menuCloseOnSelect) {
  onClose()
  }
  },
  - [onClose, onClickProp, menuCloseOnSelect, menuItemCloseOnSelect],
  + [onClose, onClickProp, menuCloseOnSelect, closeOnSelect],
  )
  const isFocused = index === focusedIndex
  @@ -485,8 +484,8 @@ export function useMenuItem(
  if (!isOpen) return
  if (isFocused && !trulyDisabled && ref.current) {
  focus(ref.current, { nextTick: true })
  - } else if (document.activeElement !== menuRef.current) {
  - menuRef.current?.focus()
  + } else if (menuRef.current && !isActiveElement(menuRef.current)) {
  + focus(menuRef.current)
  }
  }, [isFocused, trulyDisabled, menuRef, isOpen])
  