Radio cannot be used alone, outside of the RadioGroup context. RadioGroup should receive only Radio components as children. The label prop is mandatory in both components and the value prop is required for the Radio component only.
<RadioGrouplabel="This is a group"> <Radio label="option 1" value="1" /> <Radio label="option 2" value="2" /> </RadioGroup>
Both components provide a disabled property. However, when set to true at the RadioGroup level, it overrides any disable configuration from the Radio level. If there is any disabled={false} prop setting among the Radio options, but the RadioGroup sets it to disabled={true}, all options are disabled.
<RadioGroup label="This is a group" disabled={true}> <Radio label="option 1" value="1" disabled={false} /> <Radio label="option 2" value="2" disabled={false} /> </RadioGroup>
It is possible to define what option is initially selected by passing the value prop to the the initialValue property of the RadioGroup.
<RadioGroup label="This is a group with second option selected initially" initialValue="2"> <Radio label="option 1" value="1" /> <Radio label="option 2 is initially selected" value="2" /> </RadioGroup>
The RadioGroup component does not provide a specific validation logic but it provides a way to include the developer validation and use the stateMessages property to display any required error message.
This is an example of handling validation when the onChange event is triggered.
exportfunctionRadioValidation(){ const[groupValidationMessages, setGroupValidationMessages]=useState({}); const onChange =useCallback((e, newValue)=>{ setGroupValidationMessages({}); if(newValue =='1'){ setGroupValidationMessages({ error:['Only second option can be marked'], }); } },[]); return( <RadioGroup label="Do not select the forbidden option" onChange={onChange} stateMessages={groupValidationMessages}> <Radio label="Do not select the forbidden option" value="1" /> <Radio label="This option can be selected" value="2" /> </RadioGroup> ); }
RadioGroup and certain other inputs, allow you to use a ref property to access some native behaviors. However, only some features are exposed. In this case, when the button is clicked, the focus is automatically set in the input below.
<RadioGroup label="This is a group with second option selected initially" initialValue="2"> <Radio label="option 1" value="1" /> <Radio label="option 2 is initially selected" value="2" /> </RadioGroup>
note
There are deprecated versions of this component. Switch to a version of the docs older than 10.0.x to view their docs.
When there are multiple options to select independently of each other. Use the checkbox component instead.
There's a large number of options (6 or more) from which users can choose. Use the dropdown component instead.
The user may select zero of the options or change their mind and unselect an option. In cases like this, consider using the checkbox component. You can also choose to add a None of the above option to the radio button group instead.
note
To display a set of mutually exclusive options from which a person can select exactly one, use radio buttons instead of checkboxes.
A radio group can be arranged vertically or horizontally depending on the page structure. By default, radio buttons are arranged vertically for easier reading.
As is the case with all input components, the label for the radio group can appear at the top (default) or on the left of the input itself.
Configure one of the radio buttons, usually the first, to be selected by default. This selection expedites the task by communicating to the user that they are required to choose an option in this set. Providing a default selection is recommended for most use cases.
There are some instances, however, when preselecting a default value is presumptuous and might result in an incorrect input. Consider the content and the default selection, how users will react to it, and the effect the selection will have on the user and the organization in both the short and long term. Avoid default selections that are presumptuous, pushy, offensive, or alienating.
Radio buttons and checkboxes are not interchangeable. Use radio buttons to select a single option from a small set of mutually exclusive options (5 or fewer). Use checkboxes when there are lists of options and the user may select any number of choices, including zero, one, or several.
Use radio buttons when only one item can be selected.
Don't use radio buttons when multiple items can be selected.
Limit the radio button's text label to a single line. We recommend using one to three words for radio button labels.
Don't truncate radio button label text with an ellipsis (...). If the label is too long for the horizontal space available, consider rewording it. You can also wrap long radio button labels to a second line. This is preferable to truncation.
Do keep radio button label text concise. If necessary, wrap to a second line.
Don't truncate radio button label text with an ellipsis.
Users can only make one selection from a radio group. This means that each choice must be clear and distinct. Avoid overlapping options.
Do make sure that options are clearly distinct.
Don't provide options that have overlapping values.
Make sure that the options you provide are comprehensive so that users can make a selection. If it's impossible to be comprehensive, offer a button labeled Other, supplemented by a type-in field.
Use an asterisk (*) to indicate required fields. The asterisk precedes the field label. This helps users to easily locate which fields are required by scanning just the left-most character of the label.
You can only add an asterisk to the radio group, not individual options.
Do use an asterisk to indicate that a field is required.
Don't use an asterisk to denote anything that is optional.
The radio button component has 2 main states: selected and unselected. The default view of a radio button group is to preselect one of the radio buttons.
Users can only select one radio button at a time. When a user makes a new selection, the previous choice is automatically deselected.
Selected state
Unselected state
Radio buttons also have states for enabled, hover, focus, active, disabled, and error.
Visual
State
Description
Enabled
Indicates to the user that the element is enabled for interaction (default).
Hover
Indicates that the user has placed a cursor over the element (desktop only).
Focus
Indicates that the user has highlighted the element, typically using an input method such as a keyboard or voice.
Active
Indicates that the user is clicking or tapping the element.
Disabled
Communicates to the user that the element is not currently available for interaction.
Error
Indicates that there has been an error related to this element. For example, a selection needs to be made in order to move forward, or a selection is invalid.
The radio button group implements the html <input type="radio">, supplemented with WAI ARIA to provide meaning for blind users. The group is designated as such with role='radiogroup', while aria-checked toggles between 'true' and 'false', depending on the state of the radio button. Labels and radio buttons are programmatically associated via a 'for/id' association. The default aria-required value of 'false' toggles to 'true' when the required checkbox is checked in Storybook.
This component adheres to the following criteria for color and zoom accessibility:
Color: The contrast ratio of textual elements against their background is above 4.5:1 as per WCAG 2.0 AA requirements.
Zoom: All content and functionality is visible at 200%.
This component has been validated to meet the WCAG 2.0 AA accessibility guidelines. However, changes made by the content author can affect accessibility conformance. For example:
When a radio group does not have a default selected the focus should move to the first radio button in the group.
Labels should be presented after the radio button.
note
There are deprecated versions of this component. Switch to a version of the docs older than 10.0.x to view their docs.
Make sure to understand the Design System components API surface, and the implications and trade-offs. Learn more in our introduction to the component API.
Position of radio group label, relative to radio options. 'top' - label will be placed above the option. 'left' - label will be placed on the left side of the options.
Value of the component. Takes precedence over initialValue. If this prop is passed, component works in controlled mode and its value will change only if this prop changes.
You can use HTML input attributes, except any that are overridden by Jutro. These attributes are assigned to the HTML input element.
<RadioGrouplabel="This is a group"> <Radio label="This is the first one" value="1" id="firstOption" /> <Radio label="This is the second one" value="2" id="secondOption" /> <Radio label="This is the third one" value="3" id="thirdOption" /> </RadioGroup>
The result of passing the id property is that it becomes part of the HTML input that is created in the HTML DOM.
Jutro inputs have implemented imperative handlers as a mechanism to provide access to some common native features that might be useful for you. The following features are available:
Set focus to allow you to set the user focus into a specific component
Blur to remove the focus from the component
Scroll to the component so that you can take the user to a specific area of the page.
These features are provided through the ref property, which exposes them as follows:
The Radio component must not be used by itself, it is only to be used under the scope of the RadioGroup component. The RadioGroup component only accepts Radio elements as child elements.
warning
Any usage different from the ones described above is not supported and might cause unexpected issues in future releases.
Precedence of disabled, displayOnly, and readOnly properties
If two or more of the properties disabled, displayOnly, and readOnly are set to true at the same time, the precedence is as follows:
Although some Jutro components might provide complementary features or a helper function to facilitate the validation process, it is your responsibility as a developer to handle the validation of any user input (using or not using the complementary helpers) and to decide what error messages to show.
Jutro components behave based on the developer implementation.
When are error messages displayed?
Error messages are only displayed when you pass them to the component through the stateMessages property. This property receives an object with the following content:
The component displays every error message provided in the same order as in the array.
When does validation occur?
This is your decision as a developer. As components do not determine when the validation is performed or when the error must be displayed, you need to implement the logic to handle it according to the project requirements, for example while the user is editing the content, when the component loses focus, and on form submission.
New @jutro/components/RadioGroup and @jutro/components/Radio components introduced. These components replace other existing Radio button related components RadioButtonField, RadioButtonCardField, ImageRadioButtonField, RadioField, and RadioGroup.
The previous Radio button related components were deprecated and moved to the @jutro/legacy package. To view their documentation, switch to an older version of the documentation.
Component
Old location
New location
RadioButtonField
@jutro/components/RadioButtonField
@jutro/legacy/components/RadioButtonField
RadioButtonCardField
@jutro/components/RadioButtonCardField
@jutro/legacy/components/RadioButtonCardField
ImageRadioButtonField
@jutro/components/ImageRadioButtonField
@jutro/legacy/components/ImageRadioButtonField
RadioField
@jutro/components/RadioField
@jutro/legacy/components/RadioField
RadioGroup
@jutro/components/RadioGroup
@jutro/legacy/components/RadioGroup
Codemods are available to automatically rename existing imports.
note
Not all the functionalities and behaviors included in the "legacy" components has been included in the new RadioGroup component.