import * as React from "react"; import styled from "styled-components"; import { useField } from "formik"; import { BaseLabel, Label, ErrorLabel, RadioButton, Box, Col } from "./index"; import { StructureProps } from "./system/unions"; type ManagedRadioButtonFieldProps = StructureProps & { caption?: string; label: string; id: string; name: string; disabled?: boolean; }; // Hide this input completely const HiddenInput = styled.input` position: absolute; opacity: 0; height: 0; width: 0; margin: 0px; `; export const ManagedRadioButtonField = ({ label, caption, id, disabled, name, ...props }: ManagedRadioButtonFieldProps) => { // This differs slightly from MangaedCheckboxField const [field, meta, { setTouched }] = useField({ name, id, value: id, type: "radio", }); // Chrome and Safari do not send blur events properly const onChange = React.useCallback( (e: React.ChangeEvent) => { setTouched(true); field.onChange(e); }, [field.onChange, setTouched] ); return ( {caption ? ( ) : null} {meta.error} ); };