> ## Documentation Index
> Fetch the complete documentation index at: https://araf.badr.co.id/llms.txt
> Use this file to discover all available pages before exploring further.

# Toggle

> A pressable button that maintains an on/off state — used for view switching, text formatting, and filter activation.

## Overview

<div style={{padding:"28px 24px",background:"#f9fafb",borderRadius:"12px",border:"1px solid #e5e7eb",display:"flex",gap:"24px",flexWrap:"wrap",alignItems:"flex-start"}}>
  <div style={{display:"flex",flexDirection:"column",gap:"12px",fontFamily:"Inter,sans-serif"}}>
    <div style={{fontSize:"12px",fontWeight:500,color:"#667085"}}>Single toggle</div>

    <div style={{display:"flex",gap:"8px"}}>
      <button style={{border:"1px solid #E5E7EB",borderRadius:"8px",padding:"8px",background:"#fff",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"}}>
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#71717A" strokeWidth="2.5">
          <path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />

          <path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />
        </svg>
      </button>

      <button style={{border:"1px solid #0479CE",borderRadius:"8px",padding:"8px",background:"#EFF8FF",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"}}>
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#0479CE" strokeWidth="2.5">
          <path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />

          <path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />
        </svg>
      </button>
    </div>
  </div>

  <div style={{display:"flex",flexDirection:"column",gap:"12px",fontFamily:"Inter,sans-serif"}}>
    <div style={{fontSize:"12px",fontWeight:500,color:"#667085"}}>Toggle group</div>

    <div style={{display:"flex",border:"1px solid #E5E7EB",borderRadius:"8px",overflow:"hidden"}}>
      <button style={{padding:"8px 12px",background:"#0479CE",color:"#fff",border:"none",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500}}>
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
          <rect x="3" y="3" width="7" height="7" />

          <rect x="14" y="3" width="7" height="7" />

          <rect x="14" y="14" width="7" height="7" />

          <rect x="3" y="14" width="7" height="7" />
        </svg>

        Grid
      </button>

      <button style={{padding:"8px 12px",background:"#fff",color:"#344054",border:"none",borderLeft:"1px solid #E5E7EB",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500}}>
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
          <line x1="8" y1="6" x2="21" y2="6" />

          <line x1="8" y1="12" x2="21" y2="12" />

          <line x1="8" y1="18" x2="21" y2="18" />

          <line x1="3" y1="6" x2="3.01" y2="6" />

          <line x1="3" y1="12" x2="3.01" y2="12" />

          <line x1="3" y1="18" x2="3.01" y2="18" />
        </svg>

        List
      </button>
    </div>
  </div>
</div>

**Toggle** is a pressable button that maintains a pressed/active state. Unlike **Switch** (which is for binary settings), Toggle is used for actions: formatting (bold/italic), view switching (grid/list), and filter activation.

<Note>
  Use `ToggleGroup` when toggles are related and should behave as a group — either `"single"` (radio-like) or `"multiple"` (checkbox-like). Use standalone `Toggle` for independent on/off states.
</Note>

***

## Installation

<CodeGroup>
  ```bash npm theme={null}
  npm install @araf-ds/core
  ```

  ```bash yarn theme={null}
  yarn add @araf-ds/core
  ```

  ```bash pnpm theme={null}
  pnpm add @araf-ds/core
  ```
</CodeGroup>

***

## Usage

```tsx theme={null}
import { Toggle, ToggleGroup, ToggleGroupItem } from "@araf-ds/core"

export default function Example() {
  return (
    <ToggleGroup type="single" defaultValue="grid">
      <ToggleGroupItem value="grid" aria-label="Grid view">
        <GridIcon size={16} />
      </ToggleGroupItem>
      <ToggleGroupItem value="list" aria-label="List view">
        <ListIcon size={16} />
      </ToggleGroupItem>
    </ToggleGroup>
  )
}
```

***

## Variants

### Single Toggle (Icon Only)

<div style={{padding:"24px",background:"#f9fafb",borderRadius:"12px",border:"1px solid #e5e7eb",display:"flex",gap:"8px",alignItems:"center"}}>
  <button style={{border:"1px solid #E5E7EB",borderRadius:"8px",padding:"8px",background:"#fff",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"}} title="Bold (off)">
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#71717A" strokeWidth="2.5">
      <path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />

      <path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />
    </svg>
  </button>

  <button style={{border:"1px solid #0479CE",borderRadius:"8px",padding:"8px",background:"#EFF8FF",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"}} title="Bold (on)">
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#0479CE" strokeWidth="2.5">
      <path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />

      <path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />
    </svg>
  </button>

  <span style={{fontSize:"12px",color:"#667085",fontFamily:"Inter,sans-serif",marginLeft:"4px"}}>Off → On</span>
</div>

```tsx theme={null}
<Toggle aria-label="Toggle bold">
  <BoldIcon size={16} />
</Toggle>
```

### With Label

<div style={{padding:"24px",background:"#f9fafb",borderRadius:"12px",border:"1px solid #e5e7eb",display:"flex",gap:"8px",alignItems:"center"}}>
  <button style={{border:"1px solid #E5E7EB",borderRadius:"8px",padding:"8px 12px",background:"#fff",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",color:"#344054",fontFamily:"Inter,sans-serif",fontWeight:500}}>
    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
      <rect x="3" y="3" width="7" height="7" />

      <rect x="14" y="3" width="7" height="7" />

      <rect x="14" y="14" width="7" height="7" />

      <rect x="3" y="14" width="7" height="7" />
    </svg>

    Grid view
  </button>

  <button style={{border:"1px solid #0479CE",borderRadius:"8px",padding:"8px 12px",background:"#EFF8FF",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",color:"#0479CE",fontFamily:"Inter,sans-serif",fontWeight:500}}>
    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
      <rect x="3" y="3" width="7" height="7" />

      <rect x="14" y="3" width="7" height="7" />

      <rect x="14" y="14" width="7" height="7" />

      <rect x="3" y="14" width="7" height="7" />
    </svg>

    Grid view
  </button>

  <span style={{fontSize:"12px",color:"#667085",fontFamily:"Inter,sans-serif"}}>Off → On</span>
</div>

```tsx theme={null}
<Toggle>
  <GridIcon size={16} />
  Grid view
</Toggle>
```

### Toggle Group — Single Select

One item can be active at a time (radio-like behavior).

<div style={{padding:"24px",background:"#f9fafb",borderRadius:"12px",border:"1px solid #e5e7eb",display:"flex",gap:"12px",alignItems:"center"}}>
  <div style={{display:"flex",border:"1px solid #E5E7EB",borderRadius:"8px",overflow:"hidden",fontFamily:"Inter,sans-serif"}}>
    <button style={{padding:"8px 12px",background:"#0479CE",color:"#fff",border:"none",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500}}>
      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
        <rect x="3" y="3" width="7" height="7" />

        <rect x="14" y="3" width="7" height="7" />

        <rect x="14" y="14" width="7" height="7" />

        <rect x="3" y="14" width="7" height="7" />
      </svg>

      Grid
    </button>

    <button style={{padding:"8px 12px",background:"#fff",color:"#344054",border:"none",borderLeft:"1px solid #E5E7EB",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500}}>
      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
        <line x1="8" y1="6" x2="21" y2="6" />

        <line x1="8" y1="12" x2="21" y2="12" />

        <line x1="8" y1="18" x2="21" y2="18" />

        <line x1="3" y1="6" x2="3.01" y2="6" />

        <line x1="3" y1="12" x2="3.01" y2="12" />

        <line x1="3" y1="18" x2="3.01" y2="18" />
      </svg>

      List
    </button>

    <button style={{padding:"8px 12px",background:"#fff",color:"#344054",border:"none",borderLeft:"1px solid #E5E7EB",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500}}>
      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
        <line x1="3" y1="4" x2="21" y2="4" />

        <line x1="3" y1="9" x2="21" y2="9" />

        <line x1="3" y1="14" x2="21" y2="14" />

        <line x1="3" y1="19" x2="21" y2="19" />
      </svg>

      Table
    </button>
  </div>
</div>

```tsx theme={null}
<ToggleGroup type="single" defaultValue="grid">
  <ToggleGroupItem value="grid" aria-label="Grid view">
    <GridIcon size={16} />
    Grid
  </ToggleGroupItem>
  <ToggleGroupItem value="list" aria-label="List view">
    <ListIcon size={16} />
    List
  </ToggleGroupItem>
  <ToggleGroupItem value="table" aria-label="Table view">
    <TableIcon size={16} />
    Table
  </ToggleGroupItem>
</ToggleGroup>
```

### Toggle Group — Multi Select (Text Formatting)

Multiple items can be active simultaneously (checkbox-like behavior).

<div style={{padding:"24px",background:"#f9fafb",borderRadius:"12px",border:"1px solid #e5e7eb",display:"flex",gap:"12px",alignItems:"center"}}>
  <div style={{display:"flex",border:"1px solid #E5E7EB",borderRadius:"8px",overflow:"hidden",fontFamily:"Inter,sans-serif"}}>
    <button style={{padding:"8px 10px",background:"#EFF8FF",color:"#0479CE",border:"none",borderRight:"1px solid #E5E7EB",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"}} title="Bold">
      <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5">
        <path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />

        <path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />
      </svg>
    </button>

    <button style={{padding:"8px 10px",background:"#fff",color:"#71717A",border:"none",borderRight:"1px solid #E5E7EB",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"}} title="Italic">
      <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
        <line x1="19" y1="4" x2="10" y2="4" />

        <line x1="14" y1="20" x2="5" y2="20" />

        <line x1="15" y1="4" x2="9" y2="20" />
      </svg>
    </button>

    <button style={{padding:"8px 10px",background:"#EFF8FF",color:"#0479CE",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"}} title="Underline">
      <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
        <path d="M6 3v7a6 6 0 0 0 6 6 6 6 0 0 0 6-6V3" />

        <line x1="4" y1="21" x2="20" y2="21" />
      </svg>
    </button>
  </div>

  <span style={{fontSize:"12px",color:"#667085",fontFamily:"Inter,sans-serif"}}>Bold + Underline active</span>
</div>

```tsx theme={null}
<ToggleGroup type="multiple">
  <ToggleGroupItem value="bold" aria-label="Bold">
    <BoldIcon size={16} />
  </ToggleGroupItem>
  <ToggleGroupItem value="italic" aria-label="Italic">
    <ItalicIcon size={16} />
  </ToggleGroupItem>
  <ToggleGroupItem value="underline" aria-label="Underline">
    <UnderlineIcon size={16} />
  </ToggleGroupItem>
</ToggleGroup>
```

### Outline Variant

<div style={{padding:"24px",background:"#f9fafb",borderRadius:"12px",border:"1px solid #e5e7eb",display:"flex",gap:"8px",alignItems:"center"}}>
  <button style={{border:"1px solid #D0D5DD",borderRadius:"8px",padding:"8px 12px",background:"#fff",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",color:"#344054",fontFamily:"Inter,sans-serif",fontWeight:500}}>
    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
      <path d="M3 6h18M3 12h18M3 18h18" />
    </svg>

    Filter
  </button>

  <button style={{border:"1px solid #0479CE",borderRadius:"8px",padding:"8px 12px",background:"#EFF8FF",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",color:"#0479CE",fontFamily:"Inter,sans-serif",fontWeight:500}}>
    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
      <path d="M3 6h18M3 12h18M3 18h18" />
    </svg>

    Filter
  </button>
</div>

```tsx theme={null}
<Toggle variant="outline">
  <FilterIcon size={16} />
  Filter
</Toggle>
```

### Sizes

<div style={{padding:"24px",background:"#f9fafb",borderRadius:"12px",border:"1px solid #e5e7eb",display:"flex",gap:"12px",alignItems:"center"}}>
  {[
      {size:"sm",padding:"5px 8px",fontSize:"12px",iconSize:12},
      {size:"md",padding:"8px 12px",fontSize:"13px",iconSize:14},
      {size:"lg",padding:"10px 14px",fontSize:"14px",iconSize:16}
    ].map(s => (
      <button key={s.size} style={{border:"1px solid #E5E7EB",borderRadius:"8px",padding:s.padding,background:"#fff",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",fontSize:s.fontSize,color:"#344054",fontFamily:"Inter,sans-serif",fontWeight:500}}>
        <svg width={s.iconSize} height={s.iconSize} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M3 6h18M3 12h18M3 18h18"/></svg>
        {s.size.toUpperCase()}
      </button>
    ))}
</div>

```tsx theme={null}
<Toggle size="sm">SM</Toggle>
<Toggle size="md">MD</Toggle>
<Toggle size="lg">LG</Toggle>
```

***

## API Reference

### Toggle

<ParamField path="pressed" type="boolean">
  Controlled pressed state.
</ParamField>

<ParamField path="onPressedChange" type="(pressed: boolean) => void">
  Callback fired when pressed state changes.
</ParamField>

<ParamField path="defaultPressed" type="boolean" default="false">
  Uncontrolled default pressed state.
</ParamField>

<ParamField path="disabled" type="boolean" default="false">
  Disables the toggle.
</ParamField>

<ParamField path="variant" type="string" default="default">
  Visual style. Values: `default` · `outline`
</ParamField>

<ParamField path="size" type="string" default="md">
  Button size. Values: `sm` · `md` · `lg`
</ParamField>

<ParamField path="aria-label" type="string">
  Accessible label — required for icon-only toggles where the visible content doesn't describe the action.
</ParamField>

### ToggleGroup

<ParamField path="type" type="string" required>
  Selection mode. `"single"` allows one active item; `"multiple"` allows many.
</ParamField>

<ParamField path="value" type="string | string[]">
  Controlled value. String for `single`, array for `multiple`.
</ParamField>

<ParamField path="onValueChange" type="(value: string | string[]) => void">
  Callback fired when selection changes.
</ParamField>

<ParamField path="defaultValue" type="string | string[]">
  Uncontrolled default value.
</ParamField>

<ParamField path="size" type="string" default="md">
  Applies to all items in the group. Values: `sm` · `md` · `lg`
</ParamField>

***

## Accessibility

* Toggle renders as a `<button>` with `aria-pressed="true|false"` reflecting the current state
* Icon-only toggles must have `aria-label` describing the action (e.g. `"Toggle bold"`, not `"B"`)
* `ToggleGroup` uses `role="group"` with `aria-label` describing the group
* Keyboard: Space/Enter toggles the focused item; Arrow keys navigate within `ToggleGroup`
* State changes are announced to screen readers via `aria-pressed`

***

## Do's & Don'ts

<CardGroup cols={2}>
  <Card title="Do" icon="check" iconType="solid" color="#16A34A">
    * Use `ToggleGroup type="single"` for mutually exclusive view modes (grid/list)
    * Use `ToggleGroup type="multiple"` for independently combinable states (bold + italic)
    * Always provide `aria-label` for icon-only toggles
    * Use Toggle for UI state (view mode, filter) and Switch for settings (on/off preferences)
  </Card>

  <Card title="Don't" icon="xmark" iconType="solid" color="#DC2626">
    * Don't use Toggle as a navigation element — use Tabs instead
    * Don't use Toggle for binary settings that persist across sessions — use Switch
    * Don't use Toggle for form submission — use a Button or Checkbox
    * Don't put too many items in a ToggleGroup — limit to 4–5 maximum
  </Card>
</CardGroup>
