Class TwToggleGroup<T>
- Namespace
- TwBlazor.Components
- Assembly
- TwBlazor.dll
A set of related toggle buttons, such as text alignment or view mode options, where one item (Multiple off) or any number of items (Multiple on) can be pressed.
[CascadingTypeParameter("T")]
public class TwToggleGroup<T> : TwBlazorComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent, IAsyncDisposable
Type Parameters
TThe type of the value each item stands for.
- Inheritance
-
TwToggleGroup<T>
- Implements
- Inherited Members
Remarks
Add a TwToggleGroupItem<T> for each option; each one renders a TwToggle, styled by
the same TwToggleTheme. Bind the pressed item with @bind-Value, or the pressed items of
a Multiple group with @bind-Values.
The group is a single Tab stop, and the arrow keys, Home and End move between its items (Arrow Left and
Arrow Right swap in a right to left layout). A single-select group follows the WAI-ARIA radio group pattern:
it is a radiogroup of radio items, and moving to an item selects it. A multiple-select group
follows the toolbar pattern: it is a group of toggle buttons with aria-pressed, and Space or
Enter presses the focused item. Give the group an accessible name with
AriaLabel or AriaLabelledBy.
Constructors
TwToggleGroup()
public TwToggleGroup()
Properties
ChildContent
Gets or sets the items of the group, each a TwToggleGroupItem<T>.
[Parameter]
public RenderFragment? ChildContent { get; set; }
Property Value
Color
Gets or sets the color of every pressed item, and of the focus ring. An item can set its own.
[Parameter]
public Color? Color { get; set; }
Property Value
Remarks
If not set, a pressed item is drawn as a raised surface on the bar, or in a neutral tint.
Deselectable
Gets or sets whether pressing the pressed item of a single-select group releases it, leaving no item pressed. Defaults to false, so a selection, once made, always stays, as in a radio group.
[Parameter]
public bool Deselectable { get; set; }
Property Value
Remarks
Releasing the pressed item clears the selection rather than re-selecting the item whose value equals
default. Because a value-type T is non-nullable at runtime, a
value-type group cannot represent "no selection" through its bound Value; a value equal to
default (0, or the first member of an enum) is therefore treated as no selection.
Disabled
Gets or sets whether every item in the group is disabled.
[Parameter]
public bool Disabled { get; set; }
Property Value
Multiple
Gets or sets whether any number of items can be pressed at once. Bind Values when this is true, and Value when it is false (the default).
[Parameter]
public bool Multiple { get; set; }
Property Value
Size
Gets or sets the size of every item. Defaults to Md.
[Parameter]
public Size? Size { get; set; }
Property Value
- Size?
Value
Gets or sets the value of the pressed item of a single-select group.
[Parameter]
public T? Value { get; set; }
Property Value
- T
Remarks
ValueChanged
Gets or sets the callback invoked when the pressed item of a single-select group changes. Releasing the pressed item of a Deselectable group passes default.
[Parameter]
public EventCallback<T?> ValueChanged { get; set; }
Property Value
Values
Gets or sets the values of the pressed items of a Multiple group.
[Parameter]
public IEnumerable<T> Values { get; set; }
Property Value
- IEnumerable<T>
ValuesChanged
Gets or sets the callback invoked when the pressed items of a Multiple group change. The values are in the order they were pressed.
[Parameter]
public EventCallback<IEnumerable<T>> ValuesChanged { get; set; }
Property Value
Variant
Gets or sets how the group and its items are drawn.
[Parameter]
public ToggleVariant? Variant { get; set; }
Property Value
Remarks
If not set, uses DefaultVariant, which defaults to Text: the items sit on a filled bar. Outlined draws a border around the group instead.
Vertical
Gets or sets whether the items are stacked top to bottom instead of laid out in a row.
[Parameter]
public bool Vertical { get; set; }
Property Value
Methods
BuildRenderTree(RenderTreeBuilder)
Renders the component to the supplied RenderTreeBuilder.
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
__builderRenderTreeBuilder
DisposeAsync()
Releases the keydown listener registered for the group.
public ValueTask DisposeAsync()
Returns
OnAfterRenderAsync(bool)
Registers a listener that stops the arrow keys, Home and End from also scrolling the page while they move between the items. Other keys, such as Tab, are left alone.
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
firstRenderbool
Returns
OnParametersSet()
Synchronizes TwBlazor.Components.TwToggleGroup`1.hasSelection with a Value supplied by the parent. The parent's value is detected by comparing against the last value the group saw: a change the group made itself while handling a click or key press already updated TwBlazor.Components.TwToggleGroup`1.lastValue, so it is not re-interpreted here.
protected override void OnParametersSet()