UNPKG

@wordpress/components

Version:
87 lines (85 loc) 3.65 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/components/src/validated-form-controls/components/combobox-control.tsx var combobox_control_exports = {}; __export(combobox_control_exports, { ValidatedComboboxControl: () => ValidatedComboboxControl }); module.exports = __toCommonJS(combobox_control_exports); var import_compose = require("@wordpress/compose"); var import_element = require("@wordpress/element"); var import_control_with_error = require("../control-with-error"); var import_combobox_control = __toESM(require("../../combobox-control")); var import_jsx_runtime = require("react/jsx-runtime"); var UnforwardedValidatedComboboxControl = ({ required, onValidate, customValidity, onChange, markWhenOptional, ...restProps }, forwardedRef) => { const validityTargetRef = (0, import_element.useRef)(null); const mergedRefs = (0, import_compose.useMergeRefs)([forwardedRef, validityTargetRef]); const valueRef = (0, import_element.useRef)(restProps.value); (0, import_element.useEffect)(() => { const input = validityTargetRef.current?.querySelector('input[role="combobox"]'); if (input) { input.required = required !== null && required !== void 0 ? required : false; } }, [required]); return ( // TODO: Bug - Missing value error is not cleared immediately on change, waits for blur. /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_control_with_error.ControlWithError, { required, markWhenOptional, ref: mergedRefs, onValidate: () => { return onValidate?.(valueRef.current); }, customValidity, getValidityTarget: () => validityTargetRef.current?.querySelector('input[role="combobox"]'), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_combobox_control.default, { __nextHasNoMarginBottom: true, __next40pxDefaultSize: true, ...restProps, onChange: (value) => { valueRef.current = value; onChange?.(value); } }) }) ); }; var ValidatedComboboxControl = (0, import_element.forwardRef)(UnforwardedValidatedComboboxControl); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ValidatedComboboxControl }); //# sourceMappingURL=combobox-control.js.map