# @asphalt-react/toggle-button

> ToggleButton

Latest version **2.16.0** (published 2026-07-28) · UNLICENSED license · 0 weekly downloads

## Install

```sh
npm install @asphalt-react/toggle-button
pnpm add @asphalt-react/toggle-button
yarn add @asphalt-react/toggle-button
bun add @asphalt-react/toggle-button
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.16.0 |
| Published | 2026-07-28 |
| First published | 2022-05-19 |
| Weekly downloads | 0 |
| License | UNLICENSED |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 62.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | UX Engineering - Web |
| Maintainers | sayantan1211, dawn29, antoniomontana, goto.abhinav, elayudhanira-gojek, yessyprmtsr, soorajj |
| Keywords | asphalt, toggle-button, component, dls, design language system |

## Links

- npm: https://www.npmjs.com/package/@asphalt-react/toggle-button
- npm.io page: https://npm.io/package/@asphalt-react/toggle-button

## Dependencies (5)

- [classnames](https://npm.io/package/classnames.md) ^2.5.1
- [prop-types](https://npm.io/package/prop-types.md) ^15.8.1
- [@asphalt-react/helper](https://npm.io/package/@asphalt-react/helper.md) ^2.16.0
- [@asphalt-react/qualifier](https://npm.io/package/@asphalt-react/qualifier.md) ^2.16.0
- [@asphalt-react/svg-normalizer](https://npm.io/package/@asphalt-react/svg-normalizer.md) ^2.16.0

## Recent versions

- 2.16.0 (latest) — 2026-07-28
- 2.0.0-alpha.29 (next) — 2023-12-15
- 2.15.1 — 2026-04-28
- 2.15.0 — 2026-04-13
- 2.14.0 — 2026-03-11
- 2.13.0 — 2026-02-19
- 2.12.2 — 2026-01-28
- 2.12.1 — 2025-12-19
- 2.12.0 — 2025-11-28
- 2.11.0 — 2025-11-10
- 2.10.0 — 2025-10-27
- 2.9.0 — 2025-10-02
- 2.8.1 — 2025-09-10
- 2.8.0 — 2025-08-14
- 2.6.0 — 2025-07-11
- … 24 more at https://npm.io/package/@asphalt-react/toggle-button/versions

## README

# ToggleButton

![npm](https://img.shields.io/npm/dt/@asphalt-react/toggle-button?style=flat-square)
[![npm version](https://badge.fury.io/js/@asphalt-react%2Ftoggle-button.svg)](https://badge.fury.io/js/@asphalt-react%2Ftoggle-button)

A ToggleButton is a digital switch to turn an option on or off. Switching between the states — as a result of direct user action or a programmatic event. The caption should always reflect the current logical state of the button.

ToggleButtons can form a group by sticking to each other which enables creating composite components using ToggleButtons.

## Usage

```jsx
import { ToggleButton } from '@asphalt-react/toggle-button'

<ToggleButton on>mute</ToggleButton>
```

## Variants

ToggleButton comes in 3 variants -

* **Text only**: ToggleButton having text caption.
* **Icon only**: Icon as caption (which we also refer as Icon ToggleButton). For space constraint uses, Icon ToggleButton also has a compact form. The compact form also supports an option to put more emphasis on the icon instead of the button.
* **Text with icon**: Text with icon (left or right to the text) as caption.

## Sizes

ToggleButton supports 4 sizes:
\- extra small (xs)
\- small (s)
\- medium (m)
\- large (l)

## Group ToggleButtons

You can group two or more toggle buttons by sticking them together using `stickStart`, `stickEnd` & `stick` props.

Set `stickEnd` to `true` on start button and `stickStart` to `true` on the end button. If you are grouping more that two buttons use `stickEnd` & `stickStart` both on all the buttons in the middle.

Use `stick` prop optionally on the end button to enhance it's style in order to make default and second button look good together. `stick` renders the toggle button without left border.

```jsx
import { ToggleButton } from '@asphalt-react/toggle-button'

<div>
    <ToggleButton on stickEnd>left align</ToggleButton>
    <ToggleButton stickStart stick>right align</ToggleButton>
<div>
```

## When to use a ToggleButton?

### ToggleButton vs Checkbox

ToggleButtons are not an alternative to Checkboxes. They are not form controls and should not appear inside a form. ToggleButtons should only manipulate local UI states, i.e. they should not directly or indirectly initiate a remote API call to change database states.

### ToggleButton vs ToggleSwitch

Both of them provide options to toggle between states. Consider the following points to choose between them:

1. Prefer ToggleSwitches to toggle states on mobile; they support swipe gestures
2. ToggleButtons fit better in designs with space constraints
3. Use ToggleButtons to programmatically toggle the state. For example, you can bind a keyboard shortcut to a *mute* button in a video player.

## Accessibility

1. ToggleButtons accept most of the [button element's attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button) such as `disabled` & `onClick` and supports [data-\* attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes).

2. ToggleButton is focusable and keyboard navigable; <kbd>tab</kbd> (or <kbd>shift</kbd>+<kbd>tab</kbd> when tabbing backwards).

3. <kbd>space</kbd> and <kbd>enter</kbd> toggles the state of ToggleButton.

4. ToggleButton has a role of “[button](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/button_role)”.

5. ToggleButton uses `aria-pressed` to assist screen readers; the on/off state of ToggleButton determines its value.

6. ToggleButton accept the aria-\* attributes [button role](https://www.w3.org/TR/wai-aria-1.1/#button).

## Accessibility must-haves

Add `aria-label` or `aria-labelledby` in Icon ToggleButton to help assistive technologies.

[comment]: # "ToggleButton Props"

## Props

### children

React node for caption

| type | required | default |
| ---- | -------- | ------- |
| node | true     | N/A     |

### seamless

Renders a seamless variant

| type | required | default |
| ---- | -------- | ------- |
| bool | false    | false   |

### on

Sets the state of button

| type | required | default |
| ---- | -------- | ------- |
| bool | false    | false   |

### size

Sets the size of button. Possible values are `"xs", "s", "m", "l"` for extra small, small, medium & large respectively

| type | required | default |
| ---- | -------- | ------- |
| enum | false    | "m"     |

### link

Renders a link ToggleButton

| type | required | default |
| ---- | -------- | ------- |
| bool | false    | false   |

### as

Link element to render. Accepts an HTML element or a React component.

| type        | required | default |
| ----------- | -------- | ------- |
| elementType | false    | "a"     |

### asProps

Accepts props & attributes for the link element.

| type   | required | default |
| ------ | -------- | ------- |
| object | false    | {}      |

### icon

Renders an Icon ToggleButton.

| type | required | default |
| ---- | -------- | ------- |
| bool | false    | false   |

### compact

Renders a ToggleButton with less spacing around.

| type | required | default |
| ---- | -------- | ------- |
| bool | false    | false   |

### emphasize

Emphasizes the icon instead of background by coloring it.
Works only for Compact Icon ToggleButton

| type | required | default |
| ---- | -------- | ------- |
| bool | false    | false   |

### qualifier

Qualifiers are icons that enhance the caption. ToggleButton prepends the qualifier by default

Accepts SVG or SVG wrapped React component. Checkout `@asphalt-react/iconpack` for SVG wrapped React components.

> ⚠️ Do not use `qualifier` to render an Icon ToggleButton, use `icon` prop instead

| type    | required | default |
| ------- | -------- | ------- |
| element | false    | null    |

### qualifierEnd

Appends qualifier to the caption

| type | required | default |
| ---- | -------- | ------- |
| bool | false    | false   |

### stickStart

Adapts to let other buttons stick to its start

| type | required | default |
| ---- | -------- | ------- |
| bool | false    | false   |

### stickEnd

Adapts to let other buttons stick to its end

| type | required | default |
| ---- | -------- | ------- |
| bool | false    | false   |

### stick

Enhances the style of the supporting button.

| type | required | default |
| ---- | -------- | ------- |
| bool | false    | false   |

### underline

Adds underline in link ToggleButton

| type | required | default |
| ---- | -------- | ------- |
| bool | false    | true    |

### brand

Applies brand intent when ToggleButton is on.

| type | required | default |
| ---- | -------- | ------- |
| bool | false    | false   |

---
_Source: https://npm.io/package/@asphalt-react/toggle-button · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
