Radios

Radios let you create a radio group.


Make radios easily

You only need two things: a name for the radio group and a list of values to used for your radio items.

Svelte
<Radios
name="fav-fruit"
radios={['apple', 'banana', 'carrot']}
/>
It doesn’t get any easier than this! 😉

Wrapped in Fieldset, as it should be

Radios wraps radio items in a <fieldset> element since they’re related. You can also provide an optional label with legend.

<Radios
name="fav-fruit"
radios={['apple', 'banana', 'carrot']}
/>

Wrapping radios in fieldset is the right thing to do!

Select your favourite fruit

Add custom labels easily

If you like to use custom labels for each radio, just pass an array of objects into the radios property instead.

Svelte
<Radios
name="fav-fruit"
radios={[
{ value: 'apple', label: '🍎 Apple'},
{ value: 'banana', label: '🍌 Banana'},
{ value: 'carrot', label: '🥕 Carrot'},
]}
/>

Check, disable, or make any radio item readonly, at your discretion

Just set checked, disabled, or readonly to true for the radio item.

Svelte
<Radios
name="fav-fruit-yay"
legend="Select your favourite fruit:"
radios={[
{ value: 'apple', checked: true, readonly: true },
{ value: 'banana'},
{ value: 'carrot'},
]}
/>
Select your favourite fruit:

Disable radios — or make them readonly — all at once

The difference between disabled and readonly radios is that disabled radios aren’t sent to the server while readonly radios are.

Svelte
<Radios
name="fav-fruit"
legend="Select your favourite fruit:"
radios={[
{ value: 'apple', checked: true },
{ value: 'banana'},
{ value: 'carrot'},
]}
readonly
/>
Select your favourite fruit:
Readonly doesn’t exist as a HTML 5 property. We made it possible by adding a hidden input.

Add an “Others” option with minimal effort

A radiogroup sometimes contain an “others” option that lets a user type into. You can create this simply by adding hasInput to the radios object.

Svelte
<Radios
name="fav-fruit"
legend="Select your favourite fruit:"
radios={[
{ value: 'apple' },
{ value: 'banana' },
{ value: 'carrot' },
{ value: 'others', hasInput: true },
]}
/>
Select your favourite fruit: