UNPKG

@react-md/menu

Version:

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

61 lines 3.53 kB
"use strict"; 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; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MenuWidget = void 0; var jsx_runtime_1 = require("react/jsx-runtime"); var react_1 = require("react"); var classnames_1 = __importDefault(require("classnames")); var utils_1 = require("@react-md/utils"); var MenuBarProvider_1 = require("./MenuBarProvider"); var styles = (0, utils_1.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 */ exports.MenuWidget = (0, react_1.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 = (0, utils_1.useKeyboardFocus)({ onFocus: propOnFocus, onKeyDown: propOnKeyDown, getDefaultFocusIndex: getDefaultFocusIndex, onSearch: onSearch, onIncrement: onIncrement, onDecrement: onDecrement, onJumpToLast: onJumpToLast, onJumpToFirst: onJumpToFirst, }), onFocus = _e.onFocus, onKeyDown = _e.onKeyDown; return ((0, jsx_runtime_1.jsx)(MenuBarProvider_1.MenuBarProvider, __assign({ root: false, defaultActiveId: props.id }, { children: (0, jsx_runtime_1.jsx)("div", __assign({ "aria-orientation": horizontal ? "horizontal" : undefined }, props, { ref: ref, role: "menu", onFocus: onFocus, onKeyDown: onKeyDown, tabIndex: tabIndex, className: (0, classnames_1.default)(styles({ horizontal: horizontal, elevated: !disableElevation }), className) }, { children: children })) }))); }); //# sourceMappingURL=MenuWidget.js.map