@wordpress/components
Version:
UI components for WordPress.
58 lines (57 loc) • 1.9 kB
JavaScript
// packages/components/src/validated-form-controls/components/toggle-group-control.tsx
import { forwardRef, useId, useRef } from "@wordpress/element";
import { ControlWithError } from "../control-with-error";
import { ToggleGroupControl } from "../../toggle-group-control";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var UnforwardedValidatedToggleGroupControl = ({
required,
onValidate,
customValidity,
onChange,
markWhenOptional,
...restProps
}, forwardedRef) => {
const validityTargetRef = useRef(null);
const valueRef = useRef(restProps.value);
const nameAttr = useId();
return /* @__PURE__ */ _jsxs("div", {
className: "components-validated-control__wrapper-with-error-delegate",
children: [/* @__PURE__ */ _jsx(ControlWithError, {
required,
markWhenOptional,
onValidate: () => {
return onValidate?.(valueRef.current);
},
customValidity,
getValidityTarget: () => validityTargetRef.current,
children: /* @__PURE__ */ _jsx(ToggleGroupControl, {
__nextHasNoMarginBottom: true,
__next40pxDefaultSize: true,
ref: forwardedRef,
onChange: (value) => {
valueRef.current = value;
onChange?.(value);
},
...restProps
})
}), /* @__PURE__ */ _jsx("input", {
className: "components-validated-control__error-delegate",
type: "radio",
ref: validityTargetRef,
required,
checked: restProps.value !== void 0,
tabIndex: -1,
name: nameAttr,
onChange: () => {
},
onFocus: (e) => {
e.target.previousElementSibling?.querySelector('[data-active-item="true"]')?.focus();
}
})]
});
};
var ValidatedToggleGroupControl = forwardRef(UnforwardedValidatedToggleGroupControl);
export {
ValidatedToggleGroupControl
};
//# sourceMappingURL=toggle-group-control.js.map