Radios
Let users select a single option from a list using the radios component.
Children are Items, each with an Input, followed by a Conditional where it reveals one.
Read the Design System guidance for radios
Import
import * as Radios from 'govuk-react/radios';Examples
Default
Code
<Radios.Field
idPrefix="where-do-you-live"
legend="Where do you live?"
>
{items}
</Radios.Field>Radio small
Code
<Radios.Field
idPrefix="where-do-you-live"
legend="Where do you live?"
small
>
{items}
</Radios.Field>Radio inline
Code
<Radios.Field
idPrefix="where-do-you-live"
legend="Have you changed your name?"
hint="This includes changing your last name or spelling your name differently."
inline
>
{(
<>
<Radios.ItemComposite id="changed-name" name="changed-name" value="yes" label="Yes" />
<Radios.ItemComposite id="changed-name-2" name="changed-name" value="no" label="No" />
</>
)}
</Radios.Field>Radio preselected
Code
<Radios.Field
idPrefix="where-do-you-live"
legend="Where do you live?"
>
{(
<>
<Radios.ItemComposite id="pre" name="pre" value="yes" label="Yes" defaultChecked />
<Radios.ItemComposite id="pre-2" name="pre" value="no" label="No" disabled />
</>
)}
</Radios.Field>Radio with hint text
Code
<Radios.Field
idPrefix="where-do-you-live"
legend="How do you want to sign in?"
>
{(
<>
<Radios.ItemComposite
id="sign-in"
name="sign-in"
value="gateway"
label="Sign in with Government Gateway"
hint="You’ll have a user ID if you’ve registered for Self Assessment or filed a tax return online before."
/>
<Radios.ItemComposite
id="sign-in-2"
name="sign-in"
value="verify"
label="Sign in with GOV.UK Verify"
hint="You’ll have an account if you’ve already proved your identity with either Barclays, CitizenSafe, Digidentity, Experian, Post Office, Royal Mail or SecureIdentity."
/>
</>
)}
</Radios.Field>With error
Code
<Radios.Field
idPrefix="where-do-you-live"
legend="Where do you live?"
errorMessage="Select the country where you live"
>
{items}
</Radios.Field>With conditional
Code
<Radios.Field
idPrefix="where-do-you-live"
legend="How would you prefer to be contacted?"
>
{(
<>
<Radios.ItemComposite
id="contact"
name="contact"
value="email"
label="Email"
defaultChecked
conditional={<InputField id="contact-by-email" name="contact-by-email" type="email" label="Email address" />}
/>
<Radios.ItemComposite
id="contact-2"
name="contact"
value="phone"
label="Phone"
conditional={<InputField id="contact-by-phone" name="contact-by-phone" type="tel" label="Phone number" />}
/>
<Radios.ItemComposite id="contact-3" name="contact" value="text" label="Text message" />
</>
)}
</Radios.Field>API reference
Radios.Root
Let users select a single option from a list using the radios component.
Children are Items, each with an Input, followed by a Conditional where it reveals one.
| Prop | Type |
|---|---|
inline | boolean |
small | boolean |
Radios.Conditional
Content revealed while its radio is checked, straight after its Item. Pass the radio's checked or defaultChecked as checked.
| Prop | Type |
|---|---|
checked | boolean |
Radios.Divider
No props of its own. Other props are passed to the element it renders.
Radios.Field
Let users select a single option from a list using the radios component.
Children are ItemComposites and Dividers.
| Prop | Type |
|---|---|
legendSize | "s" | "m" | "l" | "xl" |
legendIsPageHeading | boolean |
small | boolean |
inline | boolean |
idPrefixRequiredThis is used to prefix the | string |
legendRequiredThe legend for the fieldset used by the radios component. | ReactNode |
hintCan be used to add a hint to the radios component. | ReactNode |
errorMessageCan be used to add an error message to the radios component. The error message component will not display if you use a falsy value for | ReactNode |
itemsPrefer children, which memoise and re-render better. | (ItemCompositeProps | { divider: any; })[] |
Radios.Hint
No props of its own. Other props are passed to the element it renders.
Radios.Input
| Prop | Type |
|---|---|
controlsThe id of the | string |
Radios.Item
No props of its own. Other props are passed to the element it renders.
Radios.ItemComposite
| Prop | Type |
|---|---|
labelRequiredThe label used by each radio item within the radios component. | ReactNode |
hintCan be used to add a hint to each radio item within the radios component. | ReactNode |
conditionalProvide additional content to reveal when the radio is checked. | ReactNode |
Radios.Label
| Prop | Type |
|---|---|
size | "s" | "m" | "l" | "xl" |
isPageHeadingWhether the label also acts as the heading for the page. | boolean |