@wordpress/components
Version:
UI components for WordPress.
43 lines (42 loc) • 1.82 kB
JavaScript
import { forwardRef, useRef } from "@wordpress/element";
import { ControlWithError } from "@wordpress/ui";
import CustomSelectControl from "../../custom-select-control/index.mjs";
import { jsx, jsxs } from "react/jsx-runtime";
// packages/components/src/validated-form-controls/components/custom-select-control.tsx
const UnforwardedValidatedCustomSelectControl = ({ required, customValidity, markWhenOptional, ...restProps }, forwardedRef) => {
const validityTargetRef = useRef(null);
const getInteractiveTarget = () => validityTargetRef.current?.previousElementSibling?.querySelector("[role=\"combobox\"]");
return /* @__PURE__ */ jsxs("div", {
className: "components-validated-control__wrapper-with-error-delegate",
ref: forwardedRef,
children: [/* @__PURE__ */ jsx(ControlWithError, {
className: "components-validated-control",
required,
markWhenOptional,
customValidity,
getValidityTarget: () => validityTargetRef.current,
getInteractiveTarget,
children: /* @__PURE__ */ jsx(CustomSelectControl, { ...restProps })
}), /* @__PURE__ */ 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__ */ jsx("option", {
value: "",
children: "No selection"
}), /* @__PURE__ */ jsx("option", {
value: "hasvalue",
children: "Has selection"
})]
})]
});
};
const ValidatedCustomSelectControl = forwardRef(UnforwardedValidatedCustomSelectControl);
ValidatedCustomSelectControl.displayName = "ValidatedCustomSelectControl";
export { ValidatedCustomSelectControl };
//# sourceMappingURL=custom-select-control.mjs.map