#Overview
Selectors are an alternative way to showcase Radio Button, Checkbox, Button or Link. They can represent a wide variety of content and it is up to the individual teams how that content inside the selectors is represented.
#Selector Radio Button
Selector Radio Buttons are used with Forms (Code).
Selector Radio Buttons have to be grouped with a <Fieldset /> and labelled with a <FieldsetLegend /> to make them accessible.
The <FieldHelpText /> has to be adeed to displays validation and help information related to the Selector Radio Buttons.
Show codeHide code
export const SelectorRadioButtonFieldsDemo = () => {
const form = useForm<{ option: string }>();
const options = {
required: false,
};
return (
<form onSubmit={form.handleSubmit(() => {})}>
<Fieldset>
<FieldsetLegend>Which fruit are your favourite?</FieldsetLegend>
<Wrapper role="presentation">
{fruit.map((item) => (
<SelectorRadioButtonField
key={item.value}
form={form}
name="option"
value={item.value}
options={options}
>
{item.label}
</SelectorRadioButtonField>
))}
</Wrapper>
<FieldHelpText form={form} name="option" />
</Fieldset>
<Button type="submit">Submit</Button>
</form>
);
};
| Name | Type | Default | Description |
|---|---|---|---|
| children * | ReactNode | - | The label of the checkbox |
| form * | UseFormReturn<TFieldValues> | - | The connected form that the form field is part of |
| name * | TFieldName | - | The name of the input being registered from the form |
| value * | PathValueImpl<TFieldValues, TFieldName> | - | the unique value of the radio button |
| defaultChecked | boolean | - | If true, the checkbox is checked initially, for uncontrolled mode, mutually exclusive with |
| disabled | boolean |
| If true, the checkbox is disabled |
| hasError | boolean |
| If true, the checkbox becomes outlined in red |
| onChange | ChangeEventHandler<HTMLInputElement> | - | The change event handler |
| options | Pick<RegisterOptions<TFieldValues, TFieldName>, "required"> |
| The options that can be set for the registration of the field |
#Outside of a form
| Name | Type | Default | Description | Controls |
|---|---|---|---|---|
| children * | ReactNode | - | The label of the radio button | |
| checked | boolean | - | If true, the radio button is checked, mutually exclusive with | |
| defaultChecked | boolean | - | If true, the radio button is checked initially, for uncontrolled mode, mutually exclusive with | |
| disabled | boolean |
| If true, the radio button is disabled | |
| hasError | boolean |
| If true, the radio button becomes outlined in red | |
| onChange | ChangeEventHandler<HTMLInputElement> | - | The change event handler | - |
#Selector Checkbox
Selector Checkboxes are used with Forms (Code).
Selector Checkboxes have to be grouped with a <Fieldset /> and labelled with a <FieldsetLegend /> to make them accessible.
The <FieldHelpText /> displays a validation message and help text related to the Selector Checkboxes.
Show codeHide code
export const SelectorCheckboxFieldsDemo = () => {
const form = useForm<{ fruit: string[] }>();
const validate = () => {
const values = form.getValues("fruit");
const amount = Array.isArray(values) ? values.length : values ? 1 : 0;
if (amount < 1) {
return "Select at least one fruit";
}
if (amount > 3) {
return "Not more than 3 fruits";
}
return true;
};
return (
<form onSubmit={form.handleSubmit(() => {})}>
<Fieldset>
<FieldsetLegend>Which fruit are your favourite?</FieldsetLegend>
<Wrapper role="presentation">
{fruit.map(({ label, value }) => (
<SelectorCheckboxField
key={value}
form={form}
name="fruit"
value={value}
defaultChecked={value === "apricot"}
options={{ validate, required: false }}
>
{label}
</SelectorCheckboxField>
))}
</Wrapper>
<FieldHelpText form={form} name="fruit">
Select between one and three fruits
</FieldHelpText>
</Fieldset>
<Button type="submit">Submit</Button>
</form>
);
};
| Name | Type | Default | Description | Controls |
|---|---|---|---|---|
| children * | ReactNode | - | The label of the checkbox | - |
| form * | UseFormReturn<TFieldValues> | - | The connected form that the form field is part of | - |
| name * | TFieldName | - | The name of the input being registered from the form | - |
| defaultChecked | boolean | - | If true, the checkbox is checked initially, for uncontrolled mode, mutually exclusive with | |
| disabled | boolean |
| If true, the checkbox is disabled | |
| onChange | ChangeEventHandler<HTMLInputElement> | - | The change event handler | - |
| options | Pick<RegisterOptions<TFieldValues, TFieldName>, "required" | "validate"> |
| The options that can be set for the registration of the field | - |
#Outside of a form
| Name | Type | Default | Description | Controls |
|---|---|---|---|---|
| children * | ReactNode | - | The label of the checkbox | |
| checked | boolean | - | If true, the checkbox is checked, for controlled mode, mutually exclusive with | |
| defaultChecked | boolean | - | If true, the checkbox is checked initially, for uncontrolled mode, mutually exclusive with | |
| disabled | boolean |
| If true, the checkbox is disabled | |
| hasError | boolean |
| If true, the checkbox becomes outlined in red | |
| onChange | ChangeEventHandler<HTMLInputElement> | - | The change event handler | - |
#Selector Button
| Name | Type | Default | Description | Controls |
|---|---|---|---|---|
| children * | ReactNode | - | The content of the button | |
| disabled | boolean |
| Disables the button | |
| isSelected | boolean | - | If true, the button looks active/selected |
#Selector Link
| Name | Type | Default | Description | Controls |
|---|---|---|---|---|
| aria-label | string | - | Defines a string value that labels the current element. | |
| children | ReactNode | - | The content of the link | |
| href | ApiRoute | string | - | The URL the link points to | - |
| isDisabled | boolean | - | If true, the link is disabled and has no pointer events | |
| isExternal | boolean |
| Sets | |
| isSelected | boolean | - | If true, the link looks active/selected | |
| minimumTargetSize | "block" | "inline" |
| Sets the minimal touch target size to comply with WCAG 2.2 AA standard
Reference: https://www.w3.org/WAI/WCAG22/Understanding/target-size-minimum.html#:~:text=inline%3A | |
| title | string | - |
#Colors
#Selector Checkbox / Radio Button
- Token
BOX#fff#111#fff#111BOX_ACTIVE#fff#111#fff#111BOX_BORDER#ddd#fff4#dee#556BOX_BORDER_ACTIVE#555#fc2#059#6bfBOX_BORDER_ERROR#e64#f75#e02#f55BOX_BORDER_FOCUS#07c#7cf#e02#f55BOX_BORDER_HOVER#000#fff#e02#f55BOX_ERROR#fff#111#fff#111BOX_FOCUS#fff#111#fff#111BOX_HOVER#fff#111#fff#111TEXT_ERROR#f75#f75#e02#f55TIME_TEXT#000#fff#059#6bfTIME_TEXT_ACTIVE#000#fff#059#6bfTIME_TEXT_ERROR#000#fff#059#6bfTIME_TEXT_FOCUS#000#fff#e02#f55TIME_TEXT_HOVER#000#fff#e02#f55
#Selector Button
- Token
BUTTON#fff#111#fff#111BUTTON_ACTIVE#fff#111#fff#111BUTTON_BORDER#ddd#fff4#dee#556BUTTON_BORDER_ACTIVE#555#fc2#059#6bfBUTTON_BORDER_ERROR#e64#f75#e02#f55BUTTON_BORDER_FOCUS#07c#7cf#e02#f55BUTTON_BORDER_HOVER#000#fff#e02#f55BUTTON_ERROR#fff#111#fff#111BUTTON_FOCUS#fff#111#fff#111BUTTON_HOVER#fff#111#fff#111TEXT_ERROR#f75#f75#e02#f55TIME_TEXT#000#fff#059#6bfTIME_TEXT_ACTIVE#000#fff#059#6bfTIME_TEXT_ERROR#000#fff#059#6bfTIME_TEXT_FOCUS#000#fff#e02#f55TIME_TEXT_HOVER#000#fff#e02#f55
#Selector Link
- Token
LINK#fff#111#fff#111LINK_ACTIVE#fff#111#fff#111LINK_BORDER#ddd#fff4#dee#556LINK_BORDER_ACTIVE#555#fc2#059#6bfLINK_BORDER_ERROR#e64#f75#e02#f55LINK_BORDER_FOCUS#07c#7cf#e02#f55LINK_BORDER_HOVER#000#fff#e02#f55LINK_ERROR#fff#111#fff#111LINK_FOCUS#fff#111#fff#111LINK_HOVER#fff#111#fff#111TEXT_ERROR#f75#f75#e02#f55TIME_TEXT#000#fff#059#6bfTIME_TEXT_ACTIVE#000#fff#059#6bfTIME_TEXT_ERROR#000#fff#059#6bfTIME_TEXT_FOCUS#000#fff#e02#f55TIME_TEXT_HOVER#000#fff#e02#f55