# react-toggle

> An elegant, accessible toggle component for React. Also a glorified checkbox.

Latest version **4.1.3** (published 2022-07-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-toggle
pnpm add react-toggle
yarn add react-toggle
bun add react-toggle
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.1.3 |
| Published | 2022-07-16 |
| First published | 2015-03-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/react-toggle) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 1.7 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Aaron Shafovaloff |
| Maintainers | bripkens, nbrempel, tgroshon, brentburgoyne, aaronshaf, thetalecrafter, th3fallen, ahstro |
| Keywords | toggle, component, react, react-component |

## Links

- npm: https://www.npmjs.com/package/react-toggle
- Repository: https://github.com/aaronshaf/react-toggle
- Issues: https://github.com/aaronshaf/react-toggle/issues
- npm.io page: https://npm.io/package/react-toggle

## Dependencies (1)

- [classnames](https://npm.io/package/classnames.md) ^2.2.5

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 4.1.3 (latest) — 2022-07-16
- 4.1.2 — 2021-03-12
- 4.1.1 — 2019-09-30
- 4.1.0 — 2019-09-30
- 4.0.2 — 2017-09-27
- 4.0.1 — 2017-05-16
- 3.0.1 — 2017-03-01
- 3.0.0 — 2017-02-14
- 2.2.1 — 2017-01-30
- 2.2.0 — 2016-11-30
- 2.1.1 — 2016-07-13
- 2.1.0 — 2016-04-14
- 2.0.1 — 2015-10-12
- 2.0.0 — 2015-10-12
- 1.2.3 — 2015-05-14
- … 24 more at https://npm.io/package/react-toggle/versions

## README

An elegant, accessible toggle component for React. Also a glorified checkbox.

See [usage and examples](http://aaronshaf.github.io/react-toggle/).

## Props

The component takes the following props.

| Prop              | Type       | Description |
|-------------------|------------|-------------|
| `checked`         | _boolean_  | If `true`, the toggle is checked. If `false`, the toggle is unchecked. Use this if you want to treat the toggle as a controlled component |
| `defaultChecked`  | _boolean_  | If `true` on initial render, the toggle is checked. If `false` on initial render, the toggle is unchecked. Use this if you want to treat the toggle as an uncontrolled component |
| `onChange`        | _function_ | Callback function to invoke when the user clicks on the toggle. The function signature should be the following: `function(e) { }`. To get the current checked status from the event, use `e.target.checked`. |
| `onFocus`         | _function_ | Callback function to invoke when field has focus. The function signature should be the following: `function(e) { }` |
| `onBlur`          | _function_ | Callback function to invoke when field loses focus. The function signature should be the following: `function(e) { }` |
| `name`            | _string_   | The value of the `name` attribute of the wrapped \<input\> element |
| `value`           | _string_   | The value of the `value` attribute of the wrapped \<input\> element |
| `id`              | _string_   | The value of the `id` attribute of the wrapped \<input\> element |
| `icons`        | _object_  | If `false`, no icons are displayed. You may also pass custom icon components in `icons={{checked: <CheckedIcon />, unchecked: <UncheckedIcon />}}` |
| `aria-labelledby` | _string_   | The value of the `aria-labelledby` attribute of the wrapped \<input\> element |
| `aria-label`      | _string_   | The value of the `aria-label` attribute of the wrapped \<input\> element |
| `disabled`        | _boolean_  | If `true`, the toggle is disabled. If `false`, the toggle is enabled |

## Installation

```bash
npm install react-toggle
```

## Usage

If you want the default styling, include the component's [CSS](./style.css) with

```javascript
import "react-toggle/style.css" // for ES6 modules
// or
require("react-toggle/style.css") // for CommonJS
```

## Development

```javascript
npm install
npm run dev
```

## Build

```javascript
npm run build
```

## License

MIT

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