Radio
Installation
yarn add @spark-web/radio
@spark-web/radio
Radios are used select a single value from several options — ususally in a form.
If multiple choices are valid, consider using a Checkbox
instead.
Examples
In order to toggle between options, all Radio components should have a matching
name
prop (unless you are using them inside of a RadioGroup
).
Size
Radio buttons are available in two sizes: small
and medium
.
RadioGroup
The RadioGroup
can be used to control a group of Radio
components. The
RadioGroup
handles the value
, tone
, message
, and disabled
state of
it's children.
Controlled
To control a group of Radio
components, wrap them with a RadioGroup
and
provide it with a value
and onChange
function.
All Radio
children must be provided with a value
.
Message and tone
The message
is used to communicate the status of a field, such as an error
message. This will be announced on focus and can be combined with a tone
to
illustrate intent. The supported tones are: critical
, positive
and
neutral
.
RadioCard
A RadioCard is an alternative to Radio. Use RadioCard where a user needs to make one selection out of several choices, and where each option requires some detailed information.
Controlled
Uncontrolled
Without description
RadioCards without a description have a lower prominence label.
Props
Radio
Prop | Type | Description |
---|---|---|
checked? | boolean | When true, the radio will be checked. |
children? | ReactNode: string | number | false | true | {} | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | The radio label content. |
data? | DataAttributeMap | Sets data attributes for the element. |
disabled? | boolean | When true, the radio will be disabled. |
size? | RadioSize: "small" | "medium" | The size of the radio. |
value? | string | The value of the radio. |
The Radio
component also extends InputHTMLAttributes
props and are not
listed here.
RadioPrimitive
Prop | Type | Description |
---|---|---|
checked? | boolean | When true, the radio will be checked. |
data? | DataAttributeMap | Sets data attributes for the element. |
disabled? | boolean | When true, the radio will be disabled. |
size? | RadioSize: "small" | "medium" | The size of the radio. Default: |
value? | string | The value of the radio. |
The CheckboxPrimitive
component also extends InputHTMLAttributes
props and
are not listed here.
RadioGroup
Prop | Type | Description |
---|---|---|
children | ReactNode: string | number | false | true | {} | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | `Radio` components. |
onChange | (selectedValue: Value) => void | Function that is fired whenever a change event is triggered on a `Radio`. |
value | string | The value of the nested radios. |
aria-describedby? | string | id(s) of the element(s) that describe the `Radio`. |
disabled? | boolean | When true, disables the group of nested radios. |
id? | string | An identifier which must be unique in the whole document. |
message? | string | Provide a message, informing the user about changes in state. |
name? | string | Name for the group of `Radio` components. |
size? | RadioSize: "small" | "medium" | The size of the nested radios. |
tone? | "critical" | "positive" | "neutral" | Provide a tone to influence elements of the field, and its input. Default: |
RadioCard
Prop | Type | Description |
---|---|---|
checked? | boolean | When true, the radio will be checked. |
children? | ReactNode: string | number | false | true | {} | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | The radio label content. |
data? | DataAttributeMap | Sets data attributes for the element. |
description? | string | The radio description. |
disabled? | boolean | When true, the radio will be disabled. |
value? | string | The value of the radio. |
The RadioCard
component also extends InputHTMLAttributes
props and are not
listed here.