Skip to main content

Toggle Component

Figma

The glu-toggle component is a switch-style input that allows users to toggle between on and off states. It supports optional left and right labels, error messaging, and supplemental helper text. The component is fully accessible, with proper ARIA attributes and keyboard interactions (using the space or Enter key), and it emits a glChange event whenever its state changes.

Basic Usage

Example 1: Simple Toggle

Result
Loading...
Live Editor
<glu-toggle
  leftLabel="Off"
  rightLabel="On"
></glu-toggle>

Toggle with Error and Helper Text

When an error occurs, you can display an error message along with supplemental helper text. In this example, the toggle shows an error state and includes an error icon next to the helper text.

Result
Loading...
Live Editor
<glu-toggle
  leftLabel="Off"
  rightLabel="On"
  error="Invalid selection"
  helperText="Please toggle the switch appropriately"
  helperIcon="error-icon"
></glu-toggle>

Disabled Toggle

Disable the toggle to prevent user interaction.

Result
Loading...
Live Editor
<glu-toggle
  leftLabel="Off"
  rightLabel="On"
  disabled
></glu-toggle>

Properties

PropertyAttributeDescriptionTypeDefault
checkedcheckedCurrent state of the togglebooleanfalse
disableddisabledDisables the togglebooleanfalse
errorerrorError message to displaystringundefined
helperIconhelper-iconHelper icon namestringundefined
helperIconVarianthelper-icon-variantHelper icon variant"outline" | "solid"'outline'
helperTexthelper-textSupplemental helper textstringundefined
leftLabelleft-labelOptional left label textstringundefined
rightLabelright-labelOptional right label textstringundefined

Events

EventDescriptionType
glChangeEmitted when toggle state changesCustomEvent<{ checked: boolean; event: Event; }>

Dependencies

Depends on

Graph


Built with StencilJS