Skip to content
GitHub11 stars

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

<div class="flex items-center space-x-2">
    <Switch id="airplane-mode" />
    <Label for="airplane-mode">Airplane Mode</Label>
</div>

Installation

dnx Blazix.Cli add switch

Usage

<Switch />

Description

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

<Field Orientation="FieldOrientation.Horizontal" Class="max-w-sm">
    <FieldContent>
        <FieldLabel for="switch-focus-mode">Share across devices</FieldLabel>
        <FieldDescription>Focus is shared across devices, and turns off when you leave the app.</FieldDescription>
    </FieldContent>
    <Switch id="switch-focus-mode" />
</Field>

Choice Card

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

<FieldGroup Class="w-full max-w-sm">
    <FieldLabel for="switch-share">
        <Field Orientation="FieldOrientation.Horizontal">

Disabled

Add the Disabled parameter to the Switch component to disable the switch. Add the data-disabled parameter to the Field component for styling.

<Field Orientation="FieldOrientation.Horizontal" data-disabled Class="w-fit">
    <Switch id="switch-disabled-unchecked" Disabled="true" />
    <FieldLabel for="switch-disabled-unchecked">Disabled</FieldLabel>
</Field>

Invalid

Add the aria-invalid parameter to the Switch component to indicate an invalid state. Add the data-invalid parameter to the Field component for styling.

You must accept the terms and conditions to continue.

<Field Orientation="FieldOrientation.Horizontal" Class="max-w-sm" data-invalid="true">
    <FieldContent>
        <FieldLabel for="switch-terms">Accept terms and conditions</FieldLabel>
        <FieldDescription>You must accept the terms and conditions to continue.</FieldDescription>
    </FieldContent>
    <Switch id="switch-terms" aria-invalid="true" />
</Field>

Size

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

<FieldGroup Class="w-full max-w-[10rem]">
    <Field Orientation="FieldOrientation.Horizontal">
        <Switch id="switch-size-sm" Size="SwitchSize.Sm" />

RTL

To enable RTL support in Blazix, see the RTL configuration guide.

Translated with AI for the demo, so it may have mistakes.

يتم مشاركة التركيز عبر الأجهزة، ويتم إيقاف تشغيله عند مغادرة التطبيق.

<Field Orientation="FieldOrientation.Horizontal" Class="max-w-sm">
    <FieldContent>
        <FieldLabel for="switch-rtl-focus-mode">@T.Label</FieldLabel>

API Reference

Switch

ParameterTypeDefault
Render RenderFragment<SwitchRenderProps>? -
Checked bool false
CheckedChanged EventCallback<bool> -
OnCheckedChange EventCallback<ValueChangeEventArgs<bool>> -
Size SwitchSize SwitchSize.Default
Disabled bool false
ReadOnly bool false
Required bool false
Name string? -
Value string? -
UncheckedValue string? -
InputId string? -
Class string? -

Other attributes are passed to the element it renders.