Skip to content

Toggle

A switch component that allows users to toggle between on/off states with smooth animations.

First release: 1.0.0 Latest update: July 1, 2025 Current version: 1.0.0

React Angular Vue Svelte HTML

Import

import { PlusToggle } from '@plusui/react';
import { PlusToggleComponent } from '@plusui/angular';
import { PlusToggle } from '@plusui/vue';
import PlusToggle from '@plusui/svelte';
<script src="https://cdn.jsdelivr.net/npm/@plusui/core"></script>

Package

@plusui/react
@plusui/angular
@plusui/vue
@plusui/svelte
@plusui/core

Docs

Changelog

Toggle Changelog

Recent changes and updates for the toggle component

v1.0.0

June 20, 2025
Feat

Added Toggle component for boolean states

  • On/off state management
  • Custom icons for active/inactive states
  • Form integration
  • Accessibility support

The Toggle component provides a switch interface that allows users to toggle between on and off states. It supports various sizes, animations, and customization options with full form integration.

A simple toggle switch.

Enable notifications
Show code

Use the label prop to add a label above the toggle.

Dark mode
Show code

Control the toggle’s size using the size prop.

Toggle sizeToggle sizeToggle size
Show code

Set the initial state using the checked prop.

Toggle stateToggle state
Show code

Control the text position using the text-position prop.

Toggle text position
Show code

Choose from different animation styles.

Animation styleAnimation styleAnimation style
Show code

Add icons to the toggle using icon props.

Theme toggle

Show code

Toggle supports various states including disabled, readonly, and error.

Disabled stateDisabled state
Show code
Readonly stateReadonly state
Show code
Error stateError state
Show code

Add descriptive text below the toggle.

Enable notifications

Show code

Make the toggle take the full width of its container.

Full width toggle
Show code

The toggle works seamlessly with forms and supports validation.

I accept the terms and conditions



Show code
Show console
  • Screen Reader:
    • Uses role="switch" to identify the toggle as a switch control.
    • aria-checked indicates the current state (true/false).
    • aria-disabled indicates if the toggle is disabled.
    • aria-invalid indicates validation state.
    • aria-labelledby and aria-describedby provide proper labeling.
  • Keyboard Navigation:
    • Space: Toggles the switch state.
    • Enter: Toggles the switch state.
    • Tab: Moves focus to/from the toggle.
  • Required Developer Actions:
    • Provide meaningful labels or text content.
    • Use caption for additional context when needed.
    • Ensure sufficient color contrast for custom styling.
NameTypeDefaultDescriptionRequired
namestring''Name attribute for form submission.No
valuestring'on'Value submitted when toggle is checked.No
checkedbooleanfalseWhether the toggle is checked.No
size'sm' | 'md' | 'lg''md'Size of the toggle.No
labelstringundefinedLabel text displayed above the toggle.No
captionstringundefinedCaption text displayed below the toggle.No
textstringundefinedText content (can also be provided via slot).No
textPosition'left' | 'right''right'Position of the text relative to the switch.No
toggleIconstringundefinedIcon displayed in the toggle dot.No
toggleActiveIconstringundefinedIcon displayed when toggle is active.No
toggleInactiveIconstringundefinedIcon displayed when toggle is inactive.No
errorbooleanfalseWhether the toggle is in error state.No
errorMessagestring''Error message displayed when in error state.No
disabledbooleanfalseWhether the toggle is disabled.No
readonlybooleanfalseWhether the toggle is readonly.No
requiredbooleanfalseWhether the toggle is required for form validation.No
fullWidthbooleanfalseWhether the toggle takes full width of its container.No
animation'default' | 'bounce' | 'smooth''default'Animation style for the toggle transition.No
customAriaLabelstringundefinedCustom aria-label for accessibility.No
NamePayload TypeDescription
plus-changeCustomEvent<void>Fired when the toggle state changes.
plus-inputCustomEvent<void>Fired when the toggle state changes (input).
plus-focusCustomEvent<void>Fired when the toggle gains focus.
plus-blurCustomEvent<void>Fired when the toggle loses focus.
plus-invalidCustomEvent<{message: string}>Fired when validation fails.
NameParametersDescription
checkValidity()NoneReturns true if the toggle is valid.
reportValidity()NoneReports validity and shows validation UI.
setCustomValidity()message: stringSets a custom validation message.
focus()options?: FocusOptionsFocuses the toggle.
blur()NoneRemoves focus from the toggle.
click()NoneProgrammatically clicks the toggle.
NameDescription
default (unnamed)The text content of the toggle.
PartDescription
baseThe main container element.
labelThe label element.
controlThe control element containing switch and text.
switchThe switch element.
dotThe dot element inside the switch.
textThe text element.
iconThe icon element in the dot.
captionThe caption element.
NameDescription
--text-colorControls the text color.
--border-colorControls the border color.
--switch-bgControls the switch background.
--switch-bg-hoverControls the hover background.
--switch-bg-activeControls the active background.
--dot-bgControls the dot background.
--dot-textControls the dot text/icon color.

Join the Community

Plus UI is built by the community. Join us on our platforms to contribute, get help, and stay up to date.