Skip to content
Glint UI

Switch

A two-state toggle for a setting that takes effect as it is flipped.

Usage

import { Switch } from "@glint/components/switch.slint";
export component AppWindow inherits Window {
in-out property <bool> notifications: true;
VerticalLayout {
alignment: center;
Switch {
label: "Push Notifications";
checked <=> root.notifications;
toggled(is-on) => {
// handle toggle change
}
}
}
}

Switch provides a sliding toggle control for turning individual binary options on or off.

Examples

Sizes

The size property adjusts the track, knob, and border radius proportionally:

  • SwitchSize.default: Standard 36 × 20 px track.
  • SwitchSize.sm: Compact 26 × 14 px track for dense toolbars or compact list items.

Disabled and invalid states

Set disabled: true to dim the switch and prevent clicks. Set invalid: true to display a destructive error border and announce an invalid state.

API Reference

Properties

PropertyTypeDefaultDescription
sizein SwitchSizeSwitchSize.defaultTrack + knob preset — sm or default.
checkedin-out boolfalseTwo-way on/off state.
labelin stringno defaultText shown to the right of the track.
disabledin boolfalseWhen true, the switch dims and stops responding.
invalidin boolfalseWhen true, the track wears the destructive border and announces itself invalid. The message that explains the error belongs to the surrounding Field — bind this to that Field's invalid.
focus-visibleout boolno defaultWhether this control holds the keyboard *and* got it from the keyboard — the focus-visible a hover surface opens on. Published because Slint reports focus only to the element holding it, so a Tooltip wrapping this control cannot read it off the scope inside (tooltip.slint).
focus-heldout boolno defaultThe same focus, still true while a popup has borrowed the window's — what a hover surface opened by this control has to gate on, since showing itself is what takes focus-visible away. See Tooltip.

Callbacks

CallbackDescription
toggled(bool)Fired with the new checked value.

Functions

FunctionDescription
focus-from-keyboard()Hand the control the keyboard the way a key press does, ring and all. A host that moves the focus onto a control because the user pressed something — Questionnaire stepping to the next question — cannot use focus(): Slint reports that as programmatic, which is how a host parking the keyboard looks, and the scope drops the ring for it. Published by every control that publishes focus-visible, for the same reason: the scope inside cannot be reached from outside the component.

Enums

EnumValues
SwitchSizesm, default

Accessibility

  • Switch role. Publishes accessible-role: switch with accessible-checkable: true and accessible-checked.
  • invalid announces the word “Invalid”. Slint 1.17 publishes no accessible-invalid, so the state rides the description channel ADR-0013 opened: the control’s own description first, then "Invalid" after it. A red border is not the announcement — this is.
  • Keyboard navigation. Space or Enter toggles state when focused.
  • Focus ring. Displays a 2px outer ring when focused via keyboard navigation.