LogoLogo
  • Release Notes
  • Downloads
  • Frequently Asked Questions
  • Developers
    • Introduction
    • Color Variables
    • Font Family
    • Vanilla JS
    • React
    • Vue
    • Angular
    • RTL Support
    • Light Mode/Dark Mode
  • Foundations
    • Typography
    • Colors
    • Icons & Visuals
    • Images
    • Layout & Breakpoints
    • Utils
    • Usability Guidelines
  • Components
    • Accordions
      • Accordion
      • Accordion Groups
    • Alert
    • Attach File
    • Avatar
    • Banner Cards
    • Breadcrumbs
    • Buttons
      • Button
      • Icon Button
      • Link Button
      • Social Media Buttons
      • Split Button
    • Checkbox
      • Checkbox Input
      • Checkbox Groups
    • Chips
    • Credit Card
    • Credit Card Input Field
    • Header
    • Interactive Banner
    • Number Field
    • Menu
    • Pagination
    • Phone Number Field
    • Progress Indicators
      • Expectation Levels
      • Progress Bar
      • Progress Circle
      • Progress Semi-Circle
    • Quick Select Field
    • Radio Buttons
      • Radio Input
      • Radio Buttons Groups
    • Search Input Field
    • Segmentation
      • Segmented Controls
      • Segmented Tabs
    • Select Input Field
    • Slider
    • Steps
      • Stepper
      • Step Indicator
    • Sticky Bar
    • Tabs
    • Text Area Field
    • Text Field
    • Toggle Switch
    • Tooltip
Powered by GitBook
On this page
  • Overview
  • Usage
  • When to use this component?
  • How it works
  • Code
  • Properties
  • Anatomy
  • Anatomy Options
  • Dos and Don'ts
Export as PDF
  1. Components

Toggle Switch

Toggle Switch is used to turn a setting on or off. It provides a clear visual indication of the current state.

PreviousText FieldNextTooltip

Last updated 1 month ago

Overview

Usage

When to use this component?

Toggle switches are used when users need to make a binary choice, such as turning a feature on or off. They are ideal for settings where changes take immediate effect without requiring additional actions, like a submit button. Common use cases include enabling or disabling notifications, switching between dark and light modes, or toggling application modes.

How it works

A toggle switch is visualized as a sliding switch that moves between two states, usually labeled "on" and "off." The switch’s position clearly indicates the current state. Toggle switches may also include optional elements like subtitles or icons to add context or functionality, enhancing user understanding of the toggle’s purpose.

Code

<dda-toggle
    checked="false"
    label_on="On"
    label_off="Off"
    size="md"
    group_name="togglegroup1"
    input_id="testId"
    custom_class=""
    component_mode=""
    aria_label="toggle"
    onchange="console.log('changed')"
></dda-toggle>
    <DdaToggle
            checked="false"
            label_on="On"
            label_off="Off"
            size="md"
            group_name="togglegroup1"
            input_id="testId"
            custom_class=""
            component_mode=""
            aria_label="toggle"
            onchange="console.log('changed')"
        ></DdaToggle>
   <DdaToggle
            checked="false"
            label_on="On"
            label_off="Off"
            size="md"
            group_name="togglegroup1"
            input_id="testId"
            custom_class=""
            component_mode=""
            aria_label="toggle"
            onchange="console.log('changed')"
        ></DdaToggle>
<dda-toggle
    checked="false"
    label_on="On"
    label_off="Off"
    size="md"
    group_name="togglegroup1"
    input_id="testId"
    custom_class=""
    component_mode=""
    aria_label="toggle"
    onchange="console.log('changed')"
></dda-toggle>```

Properties

Property
Description
Type

aria_label

Defines an accessible label for screen readers, providing additional context for users with assistive technologies.

string

checked

Determines whether the toggle switch is initially checked (on) or not (off).

boolean

component_mode

A mode or variant setting that might be used to apply different styles or behaviors based on predefined themes or configurations.

string

custom_class

Allows adding custom CSS classes to modify the appearance of the toggle. Defaults to an empty string.

string

group_name

Specifies the name attribute for the input, which is useful when grouping multiple toggle buttons together (e.g., in a radio group).

string

input_id

Sets the id attribute for the input element, allowing it to be uniquely identified in the DOM.

string

size

Defines the size of the toggle switch. Possible values could be 'sm', 'md', or 'lg'.

string

Anatomy

Anatomy Options

Toggle Switch: The main component that allows users to switch between two states.

Knob: The circular element that moves to indicate the toggle state.

Toggle Label: The primary label that describes the purpose of the toggle.

Subtitle: Additional information or description to clarify the function of the toggle.

Dos and Don'ts

Dos
Don'ts

Use toggle switches for settings that can be turned on or off.

Don't use toggle switches for actions that require multiple steps or confirmation.

Label each toggle switch clearly to indicate its function.

Avoid using ambiguous or unclear labels for toggle switches.

Ensure toggle switches are large enough to be easily tappable or clickable.

Don't make toggle switches too small to interact with comfortably.

Provide a clear visual indication of the toggle switch's state.

Don't leave users guessing whether a feature is enabled or disabled.

Group related toggle switches together visually and logically.

Don't scatter related toggle switches throughout different parts of the UI.

Use consistent spacing between toggle switches in the same group.

Don't place toggle switches too close together or too far apart, which can hinder usability.

Include appropriate aria-labels for accessibility.

Don't neglect accessibility requirements such as focus states and keyboard navigation.

Ensure each toggle switch has sufficient contrast against its background.

Avoid using low contrast that can make the toggle switches difficult to see.