<cs-radio-group>
StableFormsSince 0.1

Radio groups wrap a set of radios so they function as a single form control with one shared value. They handle keyboard navigation, labeling, and validation for the group as a whole.

Light roast Medium roast Dark roast

Examples

Initial Value

Use the value attribute on the radio group to set the initially selected radio. Match it to the value of the radio that should start checked, just like native HTML.

Light roast Medium roast Dark roast

To target checked radios with CSS, use the :state(checked) selector.

Hint

Add descriptive hint to a radio group with the hint attribute. For hints that contain HTML, use the hint slot instead.

Light roast Medium roast Dark roast

Radio Buttons

Set the appearance attribute to button on all radios to render a radio button group.

Light Dark Auto Light Dark Auto

Disabled

To disable the entire radio group, add the disabled attribute to the radio group.

Standard Express Overnight

To disable individual options, add the disabled attribute to the respective options.

Standard Express Overnight

Orientation

The default orientation for radio items is vertical. Set the orientation to horizontal to lay items out on the same row.

Standard Express Overnight

Size

The size of radios will be determined by the Radio Group’s size attribute.

Light roast Medium roast Dark roast Light roast Medium roast Dark roast Light roast Medium roast Dark roast Light roast Medium roast Dark roast Light roast Medium roast Dark roast

If you need to have radios of varying sizes, place the size attribute on individual radio items instead.

Extra Small Small Medium Large Extra Large

Validation

Set the required attribute to make selecting an option mandatory. If a value has not been selected, it will prevent the form from submitting and display an error message.

Light roast Medium roast Dark roast
Submit

Custom Validity

Use the setCustomValidity() method to set a custom validation message. This will prevent the form from submitting and make the browser display the error message you provide. To clear the error, call this function with an empty string.

Light roast Medium roast Dark roast
Submit

API

Importing

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.

npm Self-Hosted React
import '@cruglobal/cornerstone-components/components/radio-group/radio-group.js';
import './cornerstone/components/radio-group/radio-group.js';
import CsRadioGroup from '@cruglobal/cornerstone-components/react/radio-group/index.js';

Slots

Learn more about using slots.

NameDescription
(default)The default slot where <cs-radio> elements are placed.
hintText that describes how to use the radio group. Alternatively, you can use the hint attribute.
labelThe radio group's label. Required for proper accessibility. Alternatively, you can use the label attribute.

Attributes & Properties

Learn more about attributes and properties.

PropertyAttributeDescriptionTypeDefaultReflects
defaultValuevalueThe default value of the form control. Primarily used for resetting the form control.string | nullYes
disableddisabledDisables the radio group and all child radios.booleanfalseYes
formBy default, form controls are associated with the nearest containing <form> element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work.HTMLFormElement | null
hinthintThe radio groups's hint. If you need to display HTML, use the hint slot instead.string''
labellabelThe radio group's label. Required for proper accessibility. If you need to display HTML, use the label slot instead.string''
namenameThe name of the radio group, submitted as a name/value pair with form data.string | nullnullYes
orientationorientationThe orientation in which to show radio items.'horizontal' | 'vertical''vertical'Yes
requiredrequiredEnsures a child radio is checked before allowing the containing form to submit.booleanfalseYes
sizesizeThe radio group's size. When present, this size will be applied to all <cs-radio> items inside.'xs' | 's' | 'm' | 'l' | 'xl'Yes
ssrHintssr-hintOnly required for SSR. Set to true if you're slotting in a hint element so the server-rendered markup includes the hint before the component hydrates on the client.booleanfalse
ssrLabelssr-labelOnly required for SSR. Set to true if you're slotting in a label element so the server-rendered markup includes the label before the component hydrates on the client.booleanfalse
validationTargetWe use the first available radio as the validationTarget similar to native HTML that shows the validation popup on the first radio element.undefined | HTMLElement
validatorsValidators are static because they have observedAttributes, essentially attributes to "watch" for changes. Whenever these attributes change, we want to be notified and update the validator.Validator[][]
valueThe current value of the radio group, submitted as a name/value pair with form data.

Methods

Learn more about methods.

NameDescriptionArguments
focus()Sets focus on the radio group.options: FocusOptions
formStateRestoreCallback()Called when the browser is trying to restore element’s state to state in which case reason is "restore", or when the browser is trying to fulfill autofill on behalf of user in which case reason is "autocomplete". In the case of "restore", state is a string, File, or FormData object previously set as the second argument to setFormValue.state: string | File | FormData | null, reason: 'autocomplete' | 'restore'
resetValidity()Reset validity is a way of removing manual custom errors and native validation.
setCustomValidity()Do not use this when creating a "Validator". This is intended for end users of components. We track manually defined custom errors so we don't clear them on accident in our validators.message: string

Events

Learn more about events.

NameDescription
changeEmitted when the radio group's selected value changes.
cs-invalidEmitted when the form control has been checked for validity and its constraints aren't satisfied.
inputEmitted when the radio group receives user input.

CSS Parts

Learn more about CSS parts.

NameDescriptionCSS selector
form-controlThe form control that wraps the label, input, and hint.::part(form-control)
form-control-inputThe element that wraps the grouped radios, styled as a flex container by default.::part(form-control-input)
form-control-labelThe label.::part(form-control-label)
hintThe hint's wrapper.::part(hint)

Dependencies

This component automatically imports the following elements. Sub-dependencies, if any exist, are included in this list.