Checkbox with the theme look.
@using Astrol.Component.Basic.Form <AstrolCheckbox @bind-Value="remember" Text="Remember me" /><AstrolCheckbox @bind-Value="news">I want to receive the <b>newsletter</b></AstrolCheckbox><AstrolCheckbox Value="true" Disabled="true" Text="Disabled" /> @* Select all: intermediate state (–) when only some are checked *@<AstrolCheckbox Value="@allSelected" Indeterminate="@someSelected" ValueChanged="SelectAll" Text="All" />@foreach (var key in items.Keys.ToList()){ var name = key; <AstrolCheckbox Value="@items[name]" ValueChanged="v => items[name] = v" Text="@name" />}@code { private bool remember = true; private bool news; private readonly Dictionary<string, bool> items = new() { ["A"] = true, ["B"] = false, ["C"] = false }; private bool allSelected => items.Values.All(v => v); private bool someSelected => items.Values.Any(v => v) && !allSelected; private void SelectAll(bool value) { foreach (var key in items.Keys.ToList()) items[key] = value; }}With @bind-Value inside an EditForm, the checkbox notifies validation of the change and turns red if it is invalid. Press Save without checking it.
<EditForm Model="terms" OnValidSubmit="Accept"> <DataAnnotationsValidator /> <AstrolCheckbox @bind-Value="terms.Accepted" Text="I accept the terms" /> <ValidationMessage For="() => terms.Accepted" /> <AstrolButton Type="ButtonType.Submit" Text="Save" /></EditForm> @code { private TermsModel terms = new(); private sealed class TermsModel { [Range(typeof(bool), "true", "true", ErrorMessage = "Accept the terms to continue.")] public bool Accepted { get; set; } }}It is a native <input type="checkbox">: it works with the keyboard (Space), screen readers and forms. AstrolGrid uses it to select rows.