Radio
What is this?β
Radio buttons are tools that customize configurations. They represent a need for the user to make a choice among a few offered options. In multiple choice forms, use radio buttons for a single option to be selected. This component is always used in a RadioGroup
context.
Examplesβ
Help Textβ
Loading...
Group Help Textβ
Loading...
Directionβ
Loading...
Disabledβ
Loading...
Errorβ
Use the error prop to define whether the user input is with error or not. It is up to you to define what triggers it. Additionally, you should add a errorText to be displayed.
Loading...
Optionalβ
Loading...
Usageβ
import { Radio, RadioGroup, useRadioState } from '@vtex/admin-ui'
function Example() {
const state = useRadioState()
return (
<RadioGroup state={state} label="Group label">
<Radio value="radio-1" label="Label" />
<Radio value="radio-2" label="Label" />
<Radio value="radio-3" label="Label" />
</RadioGroup>
)
}
Radio Propsβ
Name | Type | Description | Required | Default |
---|---|---|---|---|
value | string, number | The value to be used in the radio button. This is the value that will be returned on form submission. | β | - |
label | string | Radio label | β | - |
helpText | ReactNode | Help text | π« | - |
checked | boolean | Same as the HTML checked attribute | π« | - |
disabled | boolean | Whether is disabled or not | π« | false |
id | string | Same as the HTML attribute | π« | - |
csx | StyleProp | Defines component styles | π« | {} |
RadioGroup Propsβ
Name | Type | Description | Required | Default |
---|---|---|---|---|
state | RadioState | Return of useRadioState hook | β | - |
label | string | Group label | β | - |
helpText | ReactNode | Help text | π« | - |
errorText | ReactNode | Error text | π« | - |
error | boolean | Whether the filed is error or not | π« | false |
direction | row, column | Direction which the children are displayed | π« | row |
optional | ReactNode | Whether the field is optional or not | π« | - |
csx | StyleProp | Defines component styles | π« | {} |
useRadioState Propsβ
A hook to help control the RadioGroup state.
Parameter Propsβ
Name | Type | Description | Required | Default |
---|---|---|---|---|
defaultValue | string, number | The initial value of the radio group. | π« | - |
setValue | (value: RadioState["value"]) => void | Function that will be called when setting the radio value state. | π« | - |
Parameter Propsβ
Name | Type | Description | Required | Default |
---|---|---|---|---|
value | string, number, null | The initial value of the radio group. | π« | - |
setValue | SetState<RadioState["value"]> | Sets the value state. | π« | - |
Accessibilityβ
Radio
has the roleradio
.RadioGroup
has roleradiogroup
.Radio
hasaria-checked
set totrue
when it's checked. Otherwise,aria-checked
is set tofalse
.- Always use
Radio
within aRadioGroup
.
Doβsβ
- Use them for single choice options.
- There should always be a pre-selected option as default.
- For more than 6 options you should use a Select.
- Donβt be ambiguous, each option should be clear.
- Mind the order of the options. Consider ordering them from most to least frequently used, simplest to most complex, or least to most risky.
- Use a "None" option if you need an unselected state.
- Consider adding an "Other" option if needed, together with a Text Input to capture the userβs needs.
- Use titles to group related controls.
- Add descriptions if the control is critical, or complex.
- Lists of controls should be vertical for better scannability.
π For UX Writing guidelines, access https://uxwriting.vtex.com