UNPKG

@react-md/menu

Version:

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

55 lines 3.16 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { jsx as _jsx } from "react/jsx-runtime"; import { forwardRef } from "react"; import cn from "classnames"; import { bem, useKeyboardFocus } from "@react-md/utils"; import { MenuBarProvider } from "./MenuBarProvider"; var styles = bem("rmd-menu"); /** * This component implements the custom keyboard movement for a * [menu widget](https://www.w3.org/TR/wai-aria-practices/#menubutton). The * {@link MenuKeyboardFocusProvider} must be a parent component for this custom * focus behavior to work. * * Note: This is probably an internal only component since the {@link Menu} has * more functionality and includes this component. * * @internal * @remarks \@since 5.0.0 */ export var MenuWidget = forwardRef(function MenuWidget(_a, ref) { var children = _a.children, propOnFocus = _a.onFocus, propOnKeyDown = _a.onKeyDown, _b = _a.tabIndex, tabIndex = _b === void 0 ? -1 : _b, _c = _a.horizontal, horizontal = _c === void 0 ? false : _c, className = _a.className, getDefaultFocusIndex = _a.getDefaultFocusIndex, onSearch = _a.onSearch, onIncrement = _a.onIncrement, onDecrement = _a.onDecrement, onJumpToLast = _a.onJumpToLast, onJumpToFirst = _a.onJumpToFirst, _d = _a.disableElevation, disableElevation = _d === void 0 ? false : _d, props = __rest(_a, ["children", "onFocus", "onKeyDown", "tabIndex", "horizontal", "className", "getDefaultFocusIndex", "onSearch", "onIncrement", "onDecrement", "onJumpToLast", "onJumpToFirst", "disableElevation"]); var _e = useKeyboardFocus({ onFocus: propOnFocus, onKeyDown: propOnKeyDown, getDefaultFocusIndex: getDefaultFocusIndex, onSearch: onSearch, onIncrement: onIncrement, onDecrement: onDecrement, onJumpToLast: onJumpToLast, onJumpToFirst: onJumpToFirst, }), onFocus = _e.onFocus, onKeyDown = _e.onKeyDown; return (_jsx(MenuBarProvider, __assign({ root: false, defaultActiveId: props.id }, { children: _jsx("div", __assign({ "aria-orientation": horizontal ? "horizontal" : undefined }, props, { ref: ref, role: "menu", onFocus: onFocus, onKeyDown: onKeyDown, tabIndex: tabIndex, className: cn(styles({ horizontal: horizontal, elevated: !disableElevation }), className) }, { children: children })) }))); }); //# sourceMappingURL=MenuWidget.js.map