UNPKG

@react-md/form

Version:

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

53 lines 3.27 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, jsxs as _jsxs } from "react/jsx-runtime"; import { forwardRef, useRef } from "react"; import cn from "classnames"; import { useIcon } from "@react-md/icon"; import { MenuItem } from "@react-md/menu"; /** * A wrapper for the `<input type="file">` element that works within menus. * * @remarks \@since 5.0.0 */ export var MenuItemFileInput = forwardRef(function MenuItemFileInput(_a, ref) { var id = _a.id, onClick = _a.onClick, onChange = _a.onChange, accept = _a.accept, _b = _a.multiple, multiple = _b === void 0 ? false : _b, children = _a.children, inputProps = _a.inputProps, _c = _a.disableRepeatableFiles, disableRepeatableFiles = _c === void 0 ? false : _c, propLeftAddon = _a.leftAddon, _d = _a.inputLabel, inputLabel = _d === void 0 ? "Upload" : _d, props = __rest(_a, ["id", "onClick", "onChange", "accept", "multiple", "children", "inputProps", "disableRepeatableFiles", "leftAddon", "inputLabel"]); var inputRef = useRef(null); var leftAddon = useIcon("upload", propLeftAddon); return (_jsxs(MenuItem, __assign({}, props, { id: "".concat(id, "-menuitem"), ref: ref, onClick: function (event) { var _a; onClick === null || onClick === void 0 ? void 0 : onClick(event); // prevent the menu from closing since you need access to the // `<input type="file">` to select a file and the menu unmounts when // hidden. event.stopPropagation(); /* istanbul-ignore-next */ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }, leftAddon: leftAddon }, { children: [children, _jsx("input", __assign({ "aria-label": inputLabel, id: id, ref: inputRef, type: "file", accept: accept, multiple: multiple, value: disableRepeatableFiles ? undefined : "", onChange: onChange }, inputProps, { onClick: function (event) { var _a; (_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onClick) === null || _a === void 0 ? void 0 : _a.call(inputProps, event); // prevent double click events since the MenuItem clicks this input event.stopPropagation(); }, className: cn("rmd-file-input", inputProps === null || inputProps === void 0 ? void 0 : inputProps.className) }))] }))); }); //# sourceMappingURL=MenuItemFileInput.js.map