ToggleGroup
Toggle buttons where one or several can be pressed, with arrow key navigation.
Examples
Single and multiple
Alignment: left
Razor
<div class="flex flex-col items-start gap-4">
<KlyToggleGroup Items="Alignments" AriaLabel="Text alignment" @bind-Value="_alignment" />
<KlyToggleGroup Items="Styles" AriaLabel="Text style" Multiple Variant="ToggleVariant.Soft" Value="@(["bold"])" />
<p class="text-sm text-(--klyroo-text-muted)" data-testid="toggle-group-state">Alignment: @(_alignment.Count > 0 ? _alignment[0] : "none")</p>
</div>
@code {
private IReadOnlyList<string> _alignment = ["left"];
private static readonly KlyToggleItem[] Alignments = [new("left", "Left"), new("center", "Center"), new("right", "Right")];
private static readonly KlyToggleItem[] Styles = [new("bold", "Bold"), new("italic", "Italic"), new("underline", "Underline")];
}Not bound
Without a binding the browser keeps what is pressed.
Razor
<KlyToggleGroup Items="Marks" AriaLabel="Text marks" Name="marks" Multiple Value="@(["bold"])" />
@code {
private static readonly KlyToggleItem[] Marks = [new("bold", "Bold"), new("italic", "Italic"), new("underline", "Underline")];
}API
KlyToggleGroup
Group of toggle buttons with single or multiple selection.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
AriaLabel |
string |
Accessible name of the group when no KlyFormField label is around. | |
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. | |
Items (required) |
IReadOnlyList |
The buttons, as KlyToggleItem . | |
Multiple |
bool |
false |
Several items can be pressed at once; otherwise pressing an item releases the others. |
Name |
string |
Form field name outside an EditForm . Inside one, the name comes from the bound expression. | |
Orientation |
KlyOrientation |
KlyOrientation. |
Direction of the layout: Horizontal or Vertical . Values: Horizontal, Vertical. |
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 |
ToggleGroupUi |
Per-instance class overrides of the slots of the toggle group, see ToggleGroupUi . They are merged after the theme and the Class parameter wins on the root slot. | |
Value (@bind-Value) |
IReadOnlyList |
The value of the control. Bind it with @bind-Value . | |
ValueExpression |
Expression |
The expression of the bound field. The compiler sets it with @bind-Value , and validation uses it to find the field. | |
Variant |
ToggleVariant |
ToggleVariant. |
Look of the toggle: Outline , Soft or Ghost . Values: Outline, Soft, Ghost. |
Ui slots
Ui takes a ToggleGroupUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Root |
Classes merged into the root slot of KlyToggleGroup , after the theme and the app configuration. |
Item |
Classes merged into the item slot of KlyToggleGroup , after the theme and the app configuration. |
Icon |
Classes merged into the icon slot of KlyToggleGroup , after the theme and the app configuration. |