UNPKG

@react-md/form

Version:

This package is for creating all the different form input types.

60 lines 2.9 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 { useKeyboardFocusableElement } from "@react-md/utils"; import { TextField } from "../text-field/TextField"; /** * This is a wrapper for the `TextField` component that can be used within * `Menu`s by updating the `onKeyDown` and `onClick` behavior. * * Note: This is **not** the `TextFieldWithMessage` since the message part is * hard to style nicely within menus. You'd most likely want to use another menu * for displaying errors. * * @remarks \@since 5.0.0 */ export var MenuItemTextField = forwardRef(function MenuItemTextField(_a, nodeRef) { var liProps = _a.liProps, onKeyDown = _a.onKeyDown, _b = _a.stretch, stretch = _b === void 0 ? true : _b, props = __rest(_a, ["liProps", "onKeyDown", "stretch"]); var refCallback = useKeyboardFocusableElement(nodeRef); return (_jsx("li", __assign({ role: "none" }, liProps, { onClick: function (event) { var _a; (_a = liProps === null || liProps === void 0 ? void 0 : liProps.onClick) === null || _a === void 0 ? void 0 : _a.call(liProps, event); event.stopPropagation(); }, className: cn("rmd-list-item rmd-menu-item", liProps === null || liProps === void 0 ? void 0 : liProps.className) }, { children: _jsx(TextField, __assign({}, props, { ref: refCallback, stretch: stretch, onKeyDown: function (event) { onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event); switch (event.key) { case "Tab": case "Escape": case " ": // do default behavior break; default: if (event.key.length === 1 || event.currentTarget.value) { event.stopPropagation(); } } } })) }))); }); //# sourceMappingURL=MenuItemTextField.js.map