Skip to content
Glint UI

Toggle

A button that stays pressed — a tool state rather than an action.

Usage

import { Toggle } from "@glint/components/toggle.slint";
import { Icon } from "@glint/components/icon.slint";
import { IconSet } from "@lucide";
export component AppWindow inherits Window {
in-out property <bool> bookmark: false;
VerticalLayout {
alignment: center;
Toggle {
text: "Bookmark";
pressed <=> root.bookmark;
toggled(is-pressed) => {
// handle state change
}
Icon {
icon: IconSet.Bookmark;
size: 16px;
}
}
}
}

Toggle renders a two-state button that stays pressed when active. It supports text labels, slotted icons, multiple visual variants, and density presets.

Examples

Variants

variant configures the background and border appearance:

  • ToggleVariant.default: Clean background that fills with accent color when pressed.
  • ToggleVariant.outline: Hairline border with subtle surface hover styling.

Sizes

size controls button height, internal padding, and font size:

  • ToggleSize.sm: Compact height (28px).
  • ToggleSize.default: Standard height (36px).
  • ToggleSize.lg: Larger touch target (40px).

Icon-only toggles

When text is omitted, Toggle automatically adopts a square aspect ratio matching its height.

API Reference

Properties

PropertyTypeDefaultDescription
textin stringno defaultLabel rendered inside.
sizein ToggleSizeToggleSize.defaultHeight + horizontal padding preset — sm, default, lg.
pressedin-out boolfalseTwo-way pressed state.
variantin ToggleVariantToggleVariant.defaultVisual style — default or outline.
disabledin boolfalseWhen true, dims and stops responding.
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 pressed 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
ToggleSizesm, default, lg
ToggleVariantdefault, outline

Accessibility

  • Checkbox role. Publishes accessible-role: checkbox with accessible-checkable: true and accessible-checked: root.pressed.
  • Keyboard navigation. Space or Enter flips the pressed state.
  • Focus ring. Displays a focus ring when active via keyboard navigation.