Switch Group
Groups related switches with a shared label, hint text, and validation state.
import {SwitchGroup} from "@qualcomm-ui/react/switch-group"Examples
Simple
Use the simple API to create a switch group using minimal markup.
If you omit the label, you should provide an aria-label prop to keep your group accessible.
<SwitchGroup hint="Select at least one" label="Notifications">
<Switch label="Email" />
<Switch label="SMS" />
<Switch label="Push" />
</SwitchGroup>
Composite
Use the composite API for granular control over the group structure.
<SwitchGroup.Root>
<SwitchGroup.Label>Notifications</SwitchGroup.Label>
<SwitchGroup.Items>
<Switch label="Email" />
<Switch label="SMS" />
<Switch label="Push" />
</SwitchGroup.Items>
<SwitchGroup.Hint>Select at least one</SwitchGroup.Hint>
</SwitchGroup.Root>
Size
The size prop controls the size of child switches. Available sizes are sm, md (default), and lg.
import type {ReactElement} from "react"
import {Switch} from "@qualcomm-ui/react/switch"
import {SwitchGroup} from "@qualcomm-ui/react/switch-group"
export function SwitchGroupSizeDemo(): ReactElement {
return (
<div className="flex flex-row gap-8">
<SwitchGroup label="Small" size="sm">
<Switch label="Email" />
<Switch label="SMS" />
</SwitchGroup>
<SwitchGroup label="Medium" size="md">
<Switch label="Email" />
<Switch label="SMS" />
</SwitchGroup>
<SwitchGroup label="Large" size="lg">
<Switch label="Email" />
<Switch label="SMS" />
</SwitchGroup>
</div>
)
}Orientation
Use the orientation prop to control the layout direction of the group. Options include:
vertical: switches are laid out in a column (default).horizontal: switches are laid out in a row.
<SwitchGroup label="Notifications" orientation="horizontal">
<Switch label="Email" />
<Switch label="SMS" />
<Switch label="Push" />
</SwitchGroup>
Indented
Set indented to add padding at the start of the group.
<SwitchGroup indented label="Notifications">
<Switch label="Email" />
<Switch label="SMS" />
<Switch label="Push" />
</SwitchGroup>
Hint
Use hint to add additional guidance or context to the user below the group.
<SwitchGroup hint="Select at least one" label="Notifications">
<Switch label="Email" />
<Switch label="SMS" />
<Switch label="Push" />
</SwitchGroup>
Error Text
Set invalid and errorText to display validation errors. The error text replaces the hint when present.
<SwitchGroup
errorText="Select at least one option"
invalid
label="Notifications"
>
<Switch label="Email" />
<Switch label="SMS" />
</SwitchGroup>
API
<SwitchGroup>
| Prop | Type | Default |
|---|---|---|
Error message displayed when invalid. | string | |
Helper text displayed below items. | string | |
Adds padding at the start of the items container. | boolean | |
Marks the group as invalid. | boolean | |
Group label text. | string | |
Layout direction for items. | | 'vertical' | 'vertical' |
Allows you to replace the component's HTML element with a different tag or component. Learn more | | ReactElement | |
The size of the group items. | | 'sm' | 'md' |
Type
stringDescription
Error message displayed when invalid.
Type
stringDescription
Helper text displayed below items.
Type
booleanDescription
Adds padding at the start of the items container.
Type
booleanDescription
Marks the group as invalid.
Type
stringDescription
Group label text.
Type
| 'vertical'
| 'horizontal'
Description
Layout direction for items.
Type
| ReactElement
| ((
props: object,
) => ReactElement)
Description
Allows you to replace the component's HTML element with a different tag or component. Learn more
Type
| 'sm'
| 'md'
| 'lg'
Description
The size of the group items.
Composite API
<SwitchGroup.Root>
| Prop | Type | Default |
|---|---|---|
Adds padding at the start of the items container. | boolean | |
Marks the group as invalid. | boolean | |
Layout direction for items. | | 'vertical' | 'vertical' |
Allows you to replace the component's HTML element with a different tag or component. Learn more | | ReactElement | |
The size of the group items. | | 'sm' | 'md' |
Type
booleanDescription
Adds padding at the start of the items container.
Type
booleanDescription
Marks the group as invalid.
Type
| 'vertical'
| 'horizontal'
Description
Layout direction for items.
Type
| ReactElement
| ((
props: object,
) => ReactElement)
Description
Allows you to replace the component's HTML element with a different tag or component. Learn more
Type
| 'sm'
| 'md'
| 'lg'
Description
The size of the group items.
| Attribute / Property | Value |
|---|---|
className | 'qui-field-group__root' |
data-invalid | |
data-part | 'root' |
data-scope | 'field-group' |
classNameValue
'qui-field-group__root'data-invalidValue
data-partValue
'root'data-scopeValue
'field-group'<SwitchGroup.Label>
Label for the field group. Renders a
<legend> element by default.| Prop | Type |
|---|---|
Allows you to replace the component's HTML element with a different tag or component. Learn more | | ReactElement |
Type
| ReactElement
| ((
props: object,
) => ReactElement)
Description
Allows you to replace the component's HTML element with a different tag or component. Learn more
| Attribute / Property | Value |
|---|---|
className | 'qui-field-group__label' |
data-part | 'label' |
data-scope | 'field-group' |
classNameValue
'qui-field-group__label'data-partValue
'label'data-scopeValue
'field-group'<SwitchGroup.Items>
Container for the field group items. Renders a
<div> element by default.| Prop | Type |
|---|---|
Allows you to replace the component's HTML element with a different tag or component. Learn more | | ReactElement |
Type
| ReactElement
| ((
props: object,
) => ReactElement)
Description
Allows you to replace the component's HTML element with a different tag or component. Learn more
| Attribute / Property | Value |
|---|---|
className | 'qui-field-group__items' |
data-indented | |
data-orientation | | 'vertical' |
data-part | 'items' |
data-scope | 'field-group' |
data-size | | 'sm' |
classNameValue
'qui-field-group__items'data-indentedValue
data-orientationValue
| 'vertical'
| 'horizontal'
data-partValue
'items'data-scopeValue
'field-group'data-sizeValue
| 'sm'
| 'md'
| 'lg'
<SwitchGroup.Hint>
Hint text for the field group. Renders a
<div> element by default.| Prop | Type |
|---|---|
Allows you to replace the component's HTML element with a different tag or component. Learn more | | ReactElement |
Type
| ReactElement
| ((
props: object,
) => ReactElement)
Description
Allows you to replace the component's HTML element with a different tag or component. Learn more
| Attribute / Property | Value |
|---|---|
className | 'qui-field-group__hint' |
data-part | 'hint' |
data-scope | 'field-group' |
classNameValue
'qui-field-group__hint'data-partValue
'hint'data-scopeValue
'field-group'<SwitchGroup.ErrorText>
Error text for the field group. Renders a
<div> element by default.Type
| LucideIcon
| ReactNode
Description
An icon to display next to the error text.
Type
| ReactElement
| ((
props: object,
) => ReactElement)
Description
Allows you to replace the component's HTML element with a different tag or component. Learn more
| Attribute / Property | Value |
|---|---|
className | 'qui-field-group__error-text' |
data-part | 'error-text' |
data-scope | 'field-group' |
classNameValue
'qui-field-group__error-text'data-partValue
'error-text'data-scopeValue
'field-group'
<fieldset>element by default.