Skip to content
Form Toggle

Toggle

A button that stays pressed. Works in the browser without being bound.

On this page

Examples

Toggle

Bold: off

Razor
<div class="flex flex-col items-start gap-3">
    <div class="flex flex-wrap items-center gap-3">
        <KlyToggle Label="Bold" @bind-Value="_bold" />
        <KlyToggle Label="Italic" Variant="ToggleVariant.Soft" />
        <KlyToggle Label="Underline" Variant="ToggleVariant.Ghost" Value="true" />
    </div>
    <p class="text-sm text-(--klyroo-text-muted)" data-testid="toggle-state">Bold: @(_bold ? "on" : "off")</p>
</div>

@code {
    private bool _bold;
}

API

KlyToggle

Button that toggles between pressed and not pressed, bound to a bool .

Parameters

Name Type Default Description
Class string Classes added to the root element, merged last so they win over the theme.
Color KlyColor "primary" Semantic color of the control: a built-in KlyColor or the name of a color you defined. When not set, Color applies, else primary. Values: primary, secondary, success, info, warning, error, neutral.
Disabled bool false Disables the control: it cannot be focused or changed and is not submitted.
Id string The id of the native control. Defaults to the one of the enclosing KlyFormField , else a generated one.
Label string Text of the button. ChildContent wins when both are given.
Name string Form field name outside an EditForm . Inside one, the name comes from the bound expression.
Required bool false Marks the control as required, for the browser and for assistive technology.
Size KlySize? Defaults to the size of the enclosing KlyFormField , or medium. Values: Xs, Sm, Md, Lg, Xl.
Ui ToggleUi Per-instance class overrides of the slots of the toggle, see ToggleUi . They are merged after the theme and the Class parameter wins on the root slot.
Value (@bind-Value) bool false The value of the control. Bind it with @bind-Value .
ValueExpression Expression<Func<bool>> The expression of the bound field. The compiler sets it with @bind-Value , and validation uses it to find the field.
Variant ToggleVariant ToggleVariant.Outline Look of the toggle: Outline , Soft or Ghost . Values: Outline, Soft, Ghost.

Slots

Name Type Description
Icon RenderFragment Icon of the button, as markup such as a KlyIcon .
ChildContent RenderFragment Content of the button.

Ui slots

Ui takes a ToggleUi with one class string per slot, merged after the theme.

Slot Styles
Base Classes merged into the base slot of KlyToggle , after the theme and the app configuration.
Label Classes merged into the label slot of KlyToggle , after the theme and the app configuration.
Icon Classes merged into the icon slot of KlyToggle , after the theme and the app configuration.