React Radio Components

Create consistent cross-browser and cross-device radios with our React radio component.

Approach#

Browser default radios are replaced with the help of <CFormCheck radio>. Radios are for selecting one option from many.

Radios#

Add the disabled attribute and the associated <label>s are automatically styled to match with a lighter color to help indicate the input's state.

1<CFormCheck type="radio" name="flexRadioDefault" id="flexRadioDefault1" label="Default radio"/>
2<CFormCheck type="radio" name="flexRadioDefault" id="flexRadioDefault2" label="Checked radio" defaultChecked/>

Disabled#

1<CFormCheck type="radio" name="flexRadioDisabled" id="flexRadioDisabled" label="Disabled radio" disabled/>
2<CFormCheck type="radio" name="flexRadioDisabled" id="flexRadioCheckedDisabled" label="Disabled checked radio" defaultChecked disabled/>

Default (stacked)#

By default, any number of radios that are immediate sibling will be vertically stacked and appropriately spaced.

1<CFormCheck type="radio" name="exampleRadios" id="exampleRadios1" value="option1" label="Default radio" defaultChecked/>
2<CFormCheck type="radio" name="exampleRadios" id="exampleRadios2" value="option2" label="Second default radio"/>
3<CFormCheck type="radio" name="exampleRadios" id="exampleRadios3" value="option3" label="Disabled radio" disabled/>

Inline#

Group radios on the same horizontal row by adding inline boolean property to any <CFormCheck radio>.

1<CFormCheck inline type="radio" name="inlineRadioOptions" id="inlineCheckbox1" value="option1" label="1"/>
2<CFormCheck inline type="radio" name="inlineRadioOptions" id="inlineCheckbox2" value="option2" label="2"/>
3<CFormCheck inline type="radio" name="inlineRadioOptions" id="inlineCheckbox3" value="option3" label="3 (disabled)" disabled/>

Without labels#

Remember to still provide some form of accessible name for assistive technologies (for instance, using aria-label).

1<CFormCheck type="radio" name="radioNoLabel" id="radioNoLabel" value="" aria-label="..."/>

Radio toggle buttons#

Create button-like radio buttons by using button boolean property on the <CFormCheck radio> component. These toggle buttons can further be grouped in a button group if needed.

1<CFormCheck button={{ color: 'secondary' }} type="radio" name="options" id="option1" autoComplete="off" label="Checked" defaultChecked/>
2<CFormCheck button={{ color: 'secondary' }} type="radio" name="options" id="option2" autoComplete="off" label="Radio"/>
3<CFormCheck button={{ color: 'secondary' }} type="radio" name="options" id="option3" autoComplete="off" label="Radio" disabled/>
4<CFormCheck button={{ color: 'secondary' }} type="radio" name="options" id="option4" autoComplete="off" label="Radio"/>

Outlined styles#

Different variants of button, such at the various outlined styles, are supported.

1<CFormCheck button={{ color: 'success', variant: 'outline' }} type="radio" name="options-outlined" id="success-outlined" autoComplete="off" label="Radio" defaultChecked/>
2<CFormCheck button={{ color: 'danger', variant: 'outline' }} type="radio" name="options-outlined" id="danger-outlined" autoComplete="off" label="Radio"/>

API#

CFormCheck#

1import { CFormCheck } from '@coreui/react'
2// or
3import CFormCheck from '@coreui/react/src/components/form/CFormCheck'
PropertyDescriptionTypeDefault
buttonCreate button-like checkboxes and radio buttons.ButtonObject-
classNameA string of all className you want applied to the component.string-
feedback
4.2.0+
Provide valuable, actionable feedback.ReactNode-
feedbackInvalid
4.2.0+
Provide valuable, actionable feedback.ReactNode-
feedbackValid
4.2.0+
Provide valuable, actionable invalid feedback when using standard HTML form validation which applied two CSS pseudo-classes, :invalid and :valid.ReactNode-
floatingLabel
4.2.0+
Provide valuable, actionable valid feedback when using standard HTML form validation which applied two CSS pseudo-classes, :invalid and :valid.ReactNode-
hitAreaSets hit area to the full area of the component.'full'-
idThe id global attribute defines an identifier (ID) that must be unique in the whole document.string-
indeterminateInput Checkbox indeterminate Property.boolean-
inlineGroup checkboxes or radios on the same horizontal row by adding.boolean-
invalidSet component validation state to invalid.boolean-
labelThe element represents a caption for a component.ReactNode-
tooltipFeedback
4.2.0+
Display validation feedback in a styled tooltip.boolean-
typeSpecifies the type of component.'checkbox' | 'radio'checkbox
validSet component validation state to valid.boolean-