UNPKG

@react-md/form

Version:

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

66 lines 3.25 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.MenuItemTextField = 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 TextField_1 = require("../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 */ exports.MenuItemTextField = (0, react_1.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 = (0, utils_1.useKeyboardFocusableElement)(nodeRef); return ((0, jsx_runtime_1.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: (0, classnames_1.default)("rmd-list-item rmd-menu-item", liProps === null || liProps === void 0 ? void 0 : liProps.className) }, { children: (0, jsx_runtime_1.jsx)(TextField_1.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