Radio
Picks exactly one option from a group. Use when the member must see all the options at once.
Health
Source
Design
Storybook
Playground
No Example
Accessibility
compliant
Platform
Universal
- Overview
- Props
- Figma
Usage
Controlled
import { useState } from "react";
import { Radio } from "murray";
function Demo() {
const [value, setValue] = useState("react");
return (
<Radio.Group
name="favoriteFramework"
label="Select your favorite framework/library"
helpText="This is anonymous"
value={value}
onChange={setValue}
>
<Radio value="react" label="React" />
<Radio value="svelte" label="Svelte" />
<Radio value="ng" label="Angular" />
<Radio value="vue" label="Vue" />
</Radio.Group>
);
}
Condensed theme
For applications with condensed theme density, this component renders in a condensed style:
Result count
Use count to show how many results an option matches, e.g. in a filter. It renders in parentheses after
the label, in a muted style, and is excluded from the accessible label. 0 is displayed as (0): an option
matching nothing keeps its count instead of silently losing it.
Usage in <Form>
On web, Checkbox and CheckboxGroupNext can be used in <Form> component and be controleld by Formik:
Playground
Loading...
tip
This component is universal, its usage is the same in
murray and murray/mobile.Radio props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| aria-label | stringundefined | Accessible label for the radio, used when no visible label is provided | ||
| aria-labelledby | stringundefined | ID of the element that labels this radio | ||
| count | numberundefined | Result count displayed in parentheses after the label, e.g. `Exempted (12)`. `0` is displayed too. Requires `label`, and is not part of the accessible label. | ||
| disabled | booleanundefined | Disable radio | ||
| helpText | ReactNode | Contents of `InputHelpTextNext` component, if not set, description is not rendered. | ||
| label | ReactNode | Contents of `InputLabelNext` component, if not set, label is not rendered. | ||
| testID | stringundefined | Mobile e2e handle: the label is not pressable on native, so a flow has to tap the radio itself. | ||
| value* | string | Radio value |
RadioGroup props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| aria-label | stringundefined | |||
| children* | ReactNode | Array of `Checkbox` eleements | ||
| defaultValue | stringundefined | Radio checked value (when uncontrolled) | ||
| error | ReactNode | Contents of `InputError` component, if not set, error is not rendered. | ||
| helpText | ReactNode | Contents of `InputHelpTextNext` component, if not set, description is not rendered. | ||
| label | ReactNode | |||
| name | stringundefined | Name of the current radio | ||
| onBlur | undefinedFocusEventHandler<HTMLDivElement> | Callback that is called when a child radio is blurred | ||
| onChange | ((value: string) => void)undefined | Callback that is called when a child radio state is changing | ||
| orientation | "vertical""horizontal"undefined | Orientation for the layout (vertical by default). Horizontal groups wrap onto extra lines when the items don't fit the available width. | ||
| required | booleanundefined | Adds required attribute to the input and a red asterisk on the right side of label, `false` by default | ||
| value | stringundefined | Radio checked value (when controlled) |