Checkbox

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

Props

Checkbox 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

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

<Checkbox name="name" label="Active?" value="yes" defaultChecked />
Copy

Events

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

<Checkbox label="Active?" onUpdate={(value, checked) => alert(`${value} - ${checked}`)} />
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 Checkbox field red.

<Checkbox error defaultChecked label="Active?" />
Copy

Custom Styles

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

Rounded

Use rounded prop to make the checkboxes circular.

<Checkbox rounded defaultChecked />
Copy

Colors

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

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

Shapes

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

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

Combniations

Try different combinations to get the checkbox you want.

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