# ToggleButton
An unstyled toggle button component with group selection support for single and multiple modes.
## Features
- Compound component API with sub-components: `Root`, `Indicator`
- Standalone toggle with boolean pressed state
- Group selection with `ToggleButtonGroup` for single and multiple modes
- Configurable `allowEmpty` to require at least one selection in a group
## Usage
```tsx
import { ToggleButton } from 'primereact/togglebutton';
import { ToggleButtonGroup } from 'primereact/togglebuttongroup';
```
```tsx
```
## Behavior
### Polymorphic Rendering
Use `as` on any sub-component to change the rendered element.
```tsx
```
Default elements: `Root`=`button`, `Indicator`=`span`, `ToggleButtonGroup`=`div`.
### Render Function Children
`Indicator` accepts a render function as children, providing access to the component instance. The instance exposes `togglebutton` (parent instance with `state.pressed`).
```tsx
{({ togglebutton }: ToggleButtonIndicatorInstance) => (togglebutton?.state.pressed ? 'On' : 'Off')}
```
## Pass Through
## API
### ToggleButtonRoot
| Attribute | Value |
| --------------- | --------------------- |
| `data-pressed` | Present when pressed |
| `data-disabled` | Present when disabled |
| `data-invalid` | Present when invalid |
| Label | Type | Description |
|:------|:------|:------|
| root | ToggleButtonRootPassThroughType> | Used to pass attributes to the root's DOM element. |
| indicator | ToggleButtonRootPassThroughType> | Used to pass attributes to the indicator's DOM element. |
### ToggleButtonIndicator
| Attribute | Value |
| --------------- | --------------------- |
| `data-pressed` | Present when pressed |
| `data-disabled` | Present when disabled |
| `data-invalid` | Present when invalid |
| Label | Type | Description |
|:------|:------|:------|
| root | ToggleButtonIndicatorPassThroughType> | Used to pass attributes to the root's DOM element. |
## Accessibility
### Screen Reader
ToggleButton uses `aria-pressed` to indicate its toggle state and `aria-disabled` when disabled. Provide `aria-label` or visible text content to give each button an accessible name. ToggleButtonGroup uses `role="group"` and should have `aria-label` to describe the group purpose.
```tsx
```
### Keyboard Support
| Key | Function |
| ---------------- | -------------------------------- |
| Space | Toggles the pressed state. |
| Enter | Toggles the pressed state. |
| Tab | Moves focus to the next element. |