{"version":3,"sources":["../src/menu-list.tsx"],"sourcesContent":["import type { HTMLUIProps } from \"@yamada-ui/core\"\nimport type { MotionPropsWithoutChildren } from \"@yamada-ui/motion\"\nimport type { KeyboardEvent, KeyboardEventHandler } from \"react\"\nimport { forwardRef, ui } from \"@yamada-ui/core\"\nimport { PopoverContent } from \"@yamada-ui/popover\"\nimport { cx, handlerAll, mergeRefs } from \"@yamada-ui/utils\"\nimport { useCallback } from \"react\"\nimport { useMenu, useMenuDescendantsContext } from \"./menu-context\"\n\nexport interface MenuListProps extends HTMLUIProps<\"ul\"> {\n  contentProps?: MotionPropsWithoutChildren\n}\n\nexport const MenuList = forwardRef<MenuListProps, \"ul\">(\n  ({ className, children, contentProps, ...rest }, ref) => {\n    const {\n      buttonRef,\n      focusedIndex,\n      menuRef,\n      setFocusedIndex,\n      styles,\n      onClose,\n    } = useMenu()\n\n    const descendants = useMenuDescendantsContext()\n\n    const activedescendantId = descendants.value(focusedIndex)?.node.id\n\n    const onNext = useCallback(() => {\n      const next = descendants.enabledNextValue(focusedIndex)\n\n      if (next) setFocusedIndex(next.index)\n    }, [descendants, focusedIndex, setFocusedIndex])\n\n    const onPrev = useCallback(() => {\n      const prev = descendants.enabledPrevValue(focusedIndex)\n\n      if (prev) setFocusedIndex(prev.index)\n    }, [descendants, focusedIndex, setFocusedIndex])\n\n    const onFirst = useCallback(() => {\n      const first = descendants.enabledFirstValue()\n\n      if (first) setFocusedIndex(first.index)\n    }, [descendants, setFocusedIndex])\n\n    const onLast = useCallback(() => {\n      const last = descendants.enabledLastValue()\n\n      if (last) setFocusedIndex(last.index)\n    }, [descendants, setFocusedIndex])\n\n    const onKeyDown = useCallback(\n      (ev: KeyboardEvent) => {\n        const actions: { [key: string]: KeyboardEventHandler } = {\n          ArrowDown: focusedIndex === -1 ? onFirst : onNext,\n          ArrowUp: focusedIndex === -1 ? onLast : onPrev,\n          End: onLast,\n          Escape: onClose,\n          Home: onFirst,\n          Tab: onClose,\n        }\n\n        const action = actions[ev.key]\n\n        if (!action) return\n\n        ev.preventDefault()\n        action(ev)\n      },\n      [focusedIndex, onClose, onFirst, onLast, onNext, onPrev],\n    )\n\n    return (\n      <PopoverContent\n        as=\"div\"\n        className=\"ui-menu__content\"\n        aria-activedescendant={activedescendantId}\n        aria-labelledby={buttonRef.current?.id}\n        role=\"menu\"\n        __css={{ ...styles.content }}\n        {...contentProps}\n        onKeyDown={handlerAll(contentProps?.onKeyDown, onKeyDown)}\n      >\n        <ui.div\n          ref={mergeRefs(menuRef, ref)}\n          className={cx(\"ui-menu__list\", className)}\n          tabIndex={-1}\n          __css={{ ...styles.list }}\n          {...rest}\n        >\n          {children}\n        </ui.div>\n      </PopoverContent>\n    )\n  },\n)\n\nMenuList.displayName = \"MenuList\"\nMenuList.__ui__ = \"MenuList\"\n"],"mappings":";;;;;;;AAGA,SAAS,YAAY,UAAU;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,IAAI,YAAY,iBAAiB;AAC1C,SAAS,mBAAmB;AA8EpB;AAvED,IAAM,WAAW;AAAA,EACtB,CAAC,EAAE,WAAW,UAAU,cAAc,GAAG,KAAK,GAAG,QAAQ;AAd3D;AAeI,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI,QAAQ;AAEZ,UAAM,cAAc,0BAA0B;AAE9C,UAAM,sBAAqB,iBAAY,MAAM,YAAY,MAA9B,mBAAiC,KAAK;AAEjE,UAAM,SAAS,YAAY,MAAM;AAC/B,YAAM,OAAO,YAAY,iBAAiB,YAAY;AAEtD,UAAI,KAAM,iBAAgB,KAAK,KAAK;AAAA,IACtC,GAAG,CAAC,aAAa,cAAc,eAAe,CAAC;AAE/C,UAAM,SAAS,YAAY,MAAM;AAC/B,YAAM,OAAO,YAAY,iBAAiB,YAAY;AAEtD,UAAI,KAAM,iBAAgB,KAAK,KAAK;AAAA,IACtC,GAAG,CAAC,aAAa,cAAc,eAAe,CAAC;AA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