Skip to main content

Overview

HuxToggle is a two-state button component commonly used for formatting controls (like bold, italic) or feature toggles. It supports both icon-only and icon-with-text configurations, with multiple variants and sizes.

Basic Usage

Basic toggle usage

Icon-Only Toggle

Variants

HuxToggle supports four visual variants through the HuxButtonVariant enum:

Primary Toggle

Primary toggle variants

Secondary Toggle

Secondary toggle variants

Outline Toggle

Outline toggle variants

Ghost Toggle

Ghost toggle variants

Sizes

Control toggle dimensions with three size options:

Small Toggle

Compact size for tight spaces (32px height). Small toggle

Medium Toggle (Default)

Default size for most use cases (40px height). Medium toggle

Large Toggle

Prominent size for important actions (48px height). Large toggle

States

Disabled State

Disabled toggle states

Custom Primary Color

Custom color toggle

API Reference

HuxToggle Properties

If label is omitted (icon-only toggle), provide semanticLabel for accessibility.

HuxToggleSize Enum

  • HuxToggleSize.small - 32px height, compact padding
  • HuxToggleSize.medium - 40px height, standard padding
  • HuxToggleSize.large - 48px height, generous padding

Accessibility

HuxToggle includes several accessibility features:

Automatic Contrast

Text and icon colors are automatically calculated to ensure WCAG AA compliance (4.5:1 contrast ratio) against any background color.

Semantic Roles

Toggles include proper semantic roles for screen readers and announce label or semanticLabel.

Focus States

Keyboard navigation support with visible focus indicators.

Disabled States

Proper disabled state handling for assistive technologies.

Best Practices

  • Use Primary for important toggles that need emphasis
  • Use Secondary for standard toggles in content areas
  • Use Outline for toggles that need visual separation
  • Use Ghost for subtle toggles in toolbars
  • Use Large for important feature toggles
  • Use Medium for most standard interactions
  • Use Small for compact toolbars or formatting controls
  • Choose clear, meaningful icons that represent the action
  • Use standard icons (bold, italic) for formatting controls
  • Add labels for actions that aren’t immediately clear
  • For icon-only toggles, always provide semanticLabel
  • Let toggles adapt to your app’s theme
  • Use primaryColor only for specific emphasis
  • Maintain consistent styling within toggle groups

Examples

Form Building

See toggles in action within forms

Text Editor

Learn how to build a formatting toolbar

Custom Theming

Apply custom colors and themes

Accessibility

Ensure your toggles are accessible