Radio

import Radio from 'frui/fields/Radio';
Copy

Props

Radio accepts all props of a standard HTML input element. See Moz for standard input attributes.

NameTypeRequiredNotes
bluebooleanNoShow blue checkbox
checkbooleanNoShow check when checked
checkedbooleanNoDefault checked state (Controlled)
circlebooleanNoShow circle when checked
classNamestringNoStandard HTML class names
defaultCheckedstringNoDefault checked state (Uncontrolled)
defaultValuestringNoDefault value (Uncontrolled)
errorstring|booleanNoAny error message
labelstringNoShows text to the right of checkbox
namestringNoUsed for react server components.
onChangeFunctionNoEvent handler when value has changed
onUpdateFunctionNoUpdate event handler
orangestringNoShow orange checkbox
passRefLegacyRefNoPasses ref to html input
roundedbooleanNoMake checkbox rounded
squarebooleanNoShow square when checked
styleCSS ObjectNoStandard CSS object
valuestringNoDefault value (Controlled)

Basics

Radio wraps the HTML standard `<input />` element. Therefore, you can use any input attributes as props.

<Radio rounded name="name" label="Yes" value="yes" defaultChecked />
Copy

Events

onUpdate is like onChange except the value is passed instead of the change event.

function Home() {
  const [ value, setValue ] = useState('yes');
  return (
    <span>
      <Radio 
        rounded 
        label="Yes" 
        value="yes" 
        checked={value === 'yes'} 
        onUpdate={value => setValue(value as string)}
      />
      <Radio 
        rounded 
        label="No" 
        value="no" 
        checked={value === 'no'} 
        onUpdate={value => setValue(value as string)}
        className="ml-4"
      />
    </span>
  )
}
Copy

On Change

The onChange event is triggered when the value has changed. The following arguments are passed to the event handler:

NameTypeSample
eventEvent Objectsee: Change Event

On Update

The onUpdate event is triggered when the value has been updated. The following arguments are passed to the event handler:

NameTypeSample
valuestring`foobar`

Errors

You can pass the error prop to highlight the Radio field red.

<Radio error rounded label="Yes" defaultChecked />
Copy

Custom Styles

You can apply rounded, colors and shapes to the Radio component.

Rounded

Use rounded prop to make the radios circular.

<Radio rounded defaultChecked />
Copy

Colors

Use blue or orange prop to change the color of radios.

<Radio blue label="Blue" defaultChecked />
Copy

Shapes

Use circle, checked or checked prop to change the color of radios.

<Radio square label="Blue" defaultChecked />
Copy

Combniations

Try different combinations to get the radios you want.

You can also add your own custom class to Radio components or use any combination of frui-field-option, frui-field-option-control, and frui-field-option-label CSS classes.