shadcn-templ 2.0 beta. Switch to templUI v1
1.7k

Switch

A control that allows the user to toggle between checked and not checked.

package examples import (

Installation

shadcn-templ add switch

Usage

import switchcomp "github.com/axadrn/shadcn-templ/v2/components/switch"
@switchcomp.Switch()

Description

Focus is shared across devices, and turns off when you leave the app.

package examples import (

Choice Card

Card-style selection where field.Label wraps the entire field.Field for a clickable card pattern.

package examples import (

Disabled

Add the Disabled prop to the Switch component to disable the switch. Add the Disabled prop to the field.Field component for styling.

package examples import (

Invalid

Add the aria-invalid attribute to the Switch component to indicate an invalid state. Add the Invalid prop to the field.Field component for styling.

You must accept the terms and conditions to continue.

package examples import (

Size

Use the Size prop to change the size of the switch.

package examples import (

API Reference

Switch

The Switch component renders the toggle as a role="switch" root with a hidden native checkbox beside it that carries form participation and label association.

Prop Type Default
Name string -
Value string on
Checked bool false
Disabled bool false
Form string -
Size SizeDefault | SizeSm SizeDefault
Class string -