Skip to content

SwitchIcon

A toggle button that swaps two icons with an animation. tabler.js (data-bs-toggle="switch-icon") toggles it on click and keeps aria-pressed in sync. Give the button an aria-label saying what it toggles.

iconA and iconB take Icon names. For anything else (a color, an SVG), use the SwitchIcon:A and SwitchIcon:B sub-components:

active starts on the second icon. loading (Tabler 1.6+) shows a spinner instead of the icons, ignores clicks and sets aria-busy="true":

a and b each have a matching block. Override one, and the other keeps rendering from its prop:

Prop Type Default Description
animation string? null fade scale flip slide-up slide-down slide-left slide-right slide-start slide-end; null swaps instantly
active bool false Starts switched on, showing icon B (active, aria-pressed="true")
loading bool false Spinner instead of the icons, clicks ignored (switch-icon-loading, aria-busy)
iconA string? null Name of the first icon, rendered with Icon inside SwitchIcon:A
iconB string? null Name of the second icon, rendered with Icon inside SwitchIcon:B

Other attributes go to the root <button class="switch-icon">.

Component Renders
SwitchIcon:A <span class="switch-icon-a">: the first, default icon
SwitchIcon:B <span class="switch-icon-b">: the toggled icon
Block Default
a SwitchIcon:A, with an Icon named iconA when set
b SwitchIcon:B, with an Icon named iconB when set
content a and b: replace it to compose freely