Components

Toggle Group

Provides a shared state to a series of toggle buttons.

Anatomy#

Import the component and use it as a single part:

Anatomytsx
import { ToggleGroup } from '@egoist/solid-base/toggle-group';

<ToggleGroup />;

The buttons inside are Toggle components. Give each one a value: the group's value is an array of the pressed toggles' values.

Examples#

Multiple#

Add the multiple prop to allow pressing more than one toggle at a time.

Controlled#

Pass value and update it from onValueChange:

Controlled toggle grouptsx
const [value, setValue] = createSignal(['left']);

<ToggleGroup value={value()} onValueChange={(next) => setValue(next)}>
  <Toggle value="left">Left</Toggle>
  <Toggle value="right">Right</Toggle>
</ToggleGroup>;

API reference#

<ToggleGroup>

Provides a shared state to a series of toggle buttons.

PropTypeDefault
valuereadonly Value[]—

The pressed state of the toggle group represented by an array of the values of all pressed toggle buttons. This is the controlled counterpart of defaultValue.

defaultValuereadonly Value[]—

The pressed state of the toggle group represented by an array of the values of all pressed toggle buttons. This is the uncontrolled counterpart of value.

onValueChange| ((groupValue: Value[], eventDetails: ToggleGroup.ChangeEventDetails) => void)—

Callback fired when the pressed states of the toggle group changes.

disabledbooleanfalse

Whether the toggle group should ignore user interaction.

orientationOrientation'horizontal'
loopFocusbooleantrue

Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.

multiplebooleanfalse

When false only one item in the group can be pressed. If any item in the group becomes pressed, the others will become unpressed. When true multiple items can be pressed.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-disabled

Present when the toggle group is disabled.

data-orientation

Indicates the orientation of the toggle group.

data-multiple

Present when the toggle group allows multiple buttons to be in the pressed state at the same time.