Navigated to /docs/ui/components/toggle-group

ToggleGroup

Compact single- or multi-select choice set rendered as connected toggles.

Preview

A live, theme-aware example rendered with the published component.

Loading preview…

Import

Import from the focused entry point below, or use the same named export from @tavojs/ui. Both are public APIs; measure the built application when comparing their bundle cost.

TSX
tsximport { ToggleGroup } from "@tavojs/ui/toggle-group";

The component import loads compiled component CSS. Enable tavoUi() for your project theme variables, or import @tavojs/ui/theme.css once for the package default theme. The equivalent CSS-safe component alias is @tavojs/ui/css/toggle-group.

When to use

Use it when

Use ToggleGroup for choices such as view mode, alignment, density, or active tools when labels are short and options fit on one line.

Choose something else when

Use Tabs when selection changes a labelled content panel, RadioGroup for conventional form choices, and Select when space is constrained or options are numerous.

Examples

These examples include imports and local state where interaction requires it. Render the exported component in a page after completing UI installation. Demo state stays in the mounted component; connect file handling, persistence, and data loading to your application as needed.

ToggleGroup example

TSXCreate: src/components/examples/ToggleGroupExample1.tsx
tsximport { createTavo } from "@tavojs/core";
import { ToggleGroup } from "@tavojs/ui/toggle-group";
import { Text } from "@tavojs/ui";

type State = { view: string };

export const ToggleGroupExample1 = createTavo<Record<string, never>, State>({
  model: () => ({ view: "grid" }),
  view: ({ state, model }) => (
    <>
      <ToggleGroup aria-label="View mode">
        <ToggleGroup.Item
          name="view"
          value="list"
          label="List"
          checked={state.view === "list"}
          onChange={() => model.set("view", "list")}
        />
        <ToggleGroup.Item
          name="view"
          value="grid"
          label="Grid"
          checked={state.view === "grid"}
          onChange={() => model.set("view", "grid")}
        />
      </ToggleGroup>
      <Text>Current view: {state.view}</Text>
    </>
  )
});

Common props and defaults

A curated starting point. The complete TypeScript API below includes additional props and compound member contracts.

PropTypeDefaultDescription
classNamestring

Optional class hook applied to the public root element owned by the component.
namestring

Configures name for this component.
valuestring | string[]

Configures value for this component.
defaultValuestring | string[]

Configures defaultValue for this component.
items{ label: Child; value: string; accessibleLabel?: string; title?: string; disabled?: boolean }[]

Configures items for this component.
type"single" | "multiple"

Configures type for this component.
allowEmptyboolean

Configures allowEmpty for this component.
fullWidthboolean

Configures fullWidth for this component.
onValueChange(value: string | string[] | undefined) => void

Configures onValueChange for this component.

Complete TypeScript API

Import from @tavojs/ui/toggle-group. Published exports: ToggleGroup, ToggleGroupItem, ToggleGroupItemComponent, ToggleGroupItemProps, ToggleGroupProps, ToggleGroupRoot, ToggleGroupValue.

ToggleGroupProps

PropertyTypeRequiredDescription
classNamestring

No

Optional class hook applied to the public root element owned by the component.

namestring

No

Configures name for this component.

valuestring | string[]

No

Configures value for this component.

defaultValuestring | string[]

No

Configures defaultValue for this component.

itemsToggleGroupItem[]

No

Configures items for this component.

type"single" | "multiple"

No

Configures type for this component.

sizeSize

No

Inherited size attribute accepted by ToggleGroup.

variantToggleVariant

No

Inherited variant attribute accepted by ToggleGroup.

fullWidthboolean

No

Configures fullWidth for this component.

allowEmptyboolean

No

Configures allowEmpty for this component.

onValueChange(value: ToggleGroupValue) => void

No

Configures onValueChange for this component.

ToggleGroupItemProps

PropertyTypeRequiredDescription
childrenChild

No

Inherited children attribute accepted by ToggleGroup.

classNamestring

No

Optional class hook applied to the public root element owned by the component.

sxSx

No

Inherited sx attribute accepted by ToggleGroup.

idstring

No

Inherited id attribute accepted by ToggleGroup.

rolestring

No

Inherited role attribute accepted by ToggleGroup.

styleRecord<string, unknown>

No

Inherited style attribute accepted by ToggleGroup.

titlestring

No

Inherited title attribute accepted by ToggleGroup.

tabIndexnumber

No

Inherited tabIndex attribute accepted by ToggleGroup.

hiddenboolean

No

Inherited hidden attribute accepted by ToggleGroup.

disabledboolean

No

Inherited disabled attribute accepted by ToggleGroup.

onClickTavoEventHandler<MouseEvent>

No

Inherited onClick attribute accepted by ToggleGroup.

onChangeTavoEventHandler<Event>

No

Inherited onChange attribute accepted by ToggleGroup.

onInputTavoEventHandler<Event>

No

Inherited onInput attribute accepted by ToggleGroup.

onKeyDownTavoEventHandler<KeyboardEvent>

No

Inherited onKeyDown attribute accepted by ToggleGroup.

onFocusTavoEventHandler<FocusEvent>

No

Inherited onFocus attribute accepted by ToggleGroup.

onBlurTavoEventHandler<FocusEvent>

No

Inherited onBlur attribute accepted by ToggleGroup.

labelChild

No

Inherited label attribute accepted by ToggleGroup.

valuestring

Yes

Configures value for this component.

namestring

No

Configures name for this component.

type"single" | "multiple"

No

Configures type for this component.

checkedboolean

No

Inherited checked attribute accepted by ToggleGroup.

defaultCheckedboolean

No

Inherited defaultChecked attribute accepted by ToggleGroup.

accessibleLabelstring

No

Inherited accessibleLabel attribute accepted by ToggleGroup.

sizeSize

No

Inherited size attribute accepted by ToggleGroup.

variantToggleVariant

No

Inherited variant attribute accepted by ToggleGroup.

State ownership and DOM target

ConcernContract
StateUse value to supply rendered state. Update it through the documented callback or native event handler. For browser-owned initial values, use defaultValue instead.
DOM targetNative input attributes target the owned form control; wrapper-specific props stay on the documented component root.

Anatomy and related components

Public compound members: Root, Item

Limitations

Use Tabs when selection changes a labelled content panel, RadioGroup for conventional form choices, and Select when space is constrained or options are numerous.

Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.

Accessibility

Form components pass through native attributes and should be paired with visible labels or accessible names.

  • Use Field, FormLabel, FormControlLabel, or aria-label for labeling.

  • Preserve native input semantics whenever possible.

  • Expose validation with error text and aria-invalid where relevant.

Component status

ContractCurrent value
Maturitystable
Categoryforms
Component import@tavojs/ui/toggle-group
Explicit CSS import@tavojs/ui/css/toggle-group
PreviewInteractive preview available on this page