A toggle, or "switch", is a button control element that allows the user to make a binary selection.

Preview

Usage

The Toggle component acts as a way to allow the User to switch between two mutually exclusive options. While it technically mirrors a Checkbox state, its effect on the system is immediate—much like a light switch immediately turns on or off the lights. In contrast, the checked state of a Checkbox won't be applied until a separate action to confirm the selection is taken.

Do

  • When its action has an instantaneous effect.

Don’t

  • When its action does not have an immediate effect on the application.
  • Selecting between 2 options. Instead, utilize a Checkbox.
  • As an alternative to a Checkbox or Radio within a Form.

Best Practices

  • A Toggle component should be used as a control within an application and provide a way to toggle between two states like a household light switch.
  • An indeterminate Toggle convey a "mixed" state that neither qualifies as toggled or not toggled. An example use case is when a Toggle acts as a "parent" of a collection of child Toggle components:
    • Toggled: all children are toggled.
    • Not toggled: all children are not toggled.
    • indeterminate: children are a mix of toggled and not toggled.

Variants and Examples

Base Styles

Sizes

With v-model

Vue API

import { DtToggle } from '@dialpad/dialtone-vue';

Slots

Name
Type
default

Slot for the main content

Props

Name
Default
Type
disabled
false
"true" | "false"

Disables the toggle interactions

id
generated unique ID
string

The id of the toggle

labelChildProps
{}
object

A set of props that are passed into the label container

labelClass
''
string|array|object

Used to customize the label container

modelValue
false
"true" | "false" | "'mixed'"

Value of the toggle

showIcon
true
"true" | "false"

Shows the icon

showLabel
true
"true" | "false"

Determines visibility of toggle label.

size
300
"200" | "300"

The size of the toggle.

toggleOnClick
true
"true" | "false"

Whether the component toggles on click. If you set this to false it means you will handle the toggling manually via the checked prop or v-model. Change events will still be triggered.

Events

Name
Type
update:modelValue
Boolean

Event fired to sync the modelValue prop with the parent component

Classes

Class
Applies to
Description

Accessibility

This component uses a native button element under the hood that has a role switch and type button to improve accessibility. See W3C guidelines for more information.

The best accessibility is semantic HTML. Most screen readers understand how to parse buttons if they're correctly formatted. When it comes to toggles, there are a few things to keep in mind:

  • All toggle buttons should have an id attribute.
  • Associate toggle labels with their buttons using the for attribute. This correlates with the toggle's id.
  • If you have a group of related toggles, use a fieldset to group them and a legend to title the group. For further information, please visit Gov.UK's article, "Using the fieldset and legend elements".

Button

The button element should be fully accessible by keyboard. To accomplish this, the DtToggle component automatically populates several ARIA attributes to the underlying button element depending on the checked and disabled states. However, if a label default slot is not used with DtToggle (without including an aria-label), a console warning error will be thrown indicating that this issue exists.

Focus & Keyboard

The button element should capture keyboard focus as long as it is not disabled (disabled prop is true). ENTER key will emit an update:modelValue event with the current value of the toggle and will change its internal checked state.

Toggle documentation last updated Thursday, June 18, 2026