UNPKG

@wordpress/components

Version:
70 lines (69 loc) • 3.27 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); // \0rolldown/runtime.js 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 __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { key = keys[i]; if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: ((k) => from[k]).bind(null, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); let _wordpress_element = require("@wordpress/element"); let _wordpress_ui = require("@wordpress/ui"); let ______custom_select_control_index_tsx = require("../../custom-select-control/index.cjs"); ______custom_select_control_index_tsx = __toESM(______custom_select_control_index_tsx); let react_jsx_runtime = require("react/jsx-runtime"); // packages/components/src/validated-form-controls/components/custom-select-control.tsx const UnforwardedValidatedCustomSelectControl = ({ required, customValidity, markWhenOptional, ...restProps }, forwardedRef) => { const validityTargetRef = (0, _wordpress_element.useRef)(null); const getInteractiveTarget = () => validityTargetRef.current?.previousElementSibling?.querySelector("[role=\"combobox\"]"); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { className: "components-validated-control__wrapper-with-error-delegate", ref: forwardedRef, children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.ControlWithError, { className: "components-validated-control", required, markWhenOptional, customValidity, getValidityTarget: () => validityTargetRef.current, getInteractiveTarget, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(______custom_select_control_index_tsx.default, { ...restProps }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", { className: "components-validated-control__error-delegate", ref: validityTargetRef, required, tabIndex: -1, "aria-hidden": "true", value: restProps.value?.key ? "hasvalue" : "", onChange: () => {}, onFocus: () => getInteractiveTarget()?.focus(), children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", { value: "", children: "No selection" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", { value: "hasvalue", children: "Has selection" })] })] }); }; const ValidatedCustomSelectControl = (0, _wordpress_element.forwardRef)(UnforwardedValidatedCustomSelectControl); ValidatedCustomSelectControl.displayName = "ValidatedCustomSelectControl"; exports.ValidatedCustomSelectControl = ValidatedCustomSelectControl; //# sourceMappingURL=custom-select-control.cjs.map