UNPKG

@react-md/menu

Version:

Create menus that auto-position themselves within the viewport and adhere to the accessibility guidelines

24 lines 928 B
import { useCallback } from "react"; import { useRefCache } from "@react-md/utils"; /** * This hook is used to create a click handler on the menu that will close the * menu when any `MenuItem` is clicked. */ export function useMenuClick(_a) { var onClick = _a.onClick, onRequestClose = _a.onRequestClose; var cache = useRefCache({ onClick: onClick, onRequestClose: onRequestClose }); return useCallback(function (event) { var _a = cache.current, onClick = _a.onClick, onRequestClose = _a.onRequestClose; if (onClick) { onClick(event); } var target = event.target; if (!target || (event.currentTarget !== target && !target.closest("[aria-haspopup]"))) { onRequestClose(); } // disabled since useRefCache // eslint-disable-next-line react-hooks/exhaustive-deps }, []); } //# sourceMappingURL=useMenuClick.js.map