Skip to content
GitHub11 stars

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

By clicking this checkbox, you agree to the terms.

<FieldGroup Class="max-w-sm">
    <Field Orientation="FieldOrientation.Horizontal">
        <Checkbox id="terms-checkbox" Name="terms-checkbox" />

Installation

dnx Blazix.Cli add checkbox

Usage

<Checkbox />

Checked State

Use Checked for uncontrolled checkboxes, or Checked and CheckedChanged to control the state.

<Checkbox @bind-Checked="_checked" />

@code {
    private bool _checked;
}

Invalid State

Set aria-invalid on the checkbox and data-invalid on the field wrapper to show the invalid styles.

<FieldGroup Class="mx-auto w-56">
    <Field Orientation="FieldOrientation.Horizontal" data-invalid="true">
        <Checkbox id="terms-checkbox-invalid" Name="terms-checkbox-invalid" aria-invalid="true" />
        <FieldLabel for="terms-checkbox-invalid">Accept terms and conditions</FieldLabel>
    </Field>
</FieldGroup>

Basic

Pair the checkbox with Field and FieldLabel for proper layout and labeling.

<FieldGroup Class="mx-auto w-56">
    <Field Orientation="FieldOrientation.Horizontal">
        <Checkbox id="terms-checkbox-basic" Name="terms-checkbox-basic" />
        <FieldLabel for="terms-checkbox-basic">Accept terms and conditions</FieldLabel>
    </Field>
</FieldGroup>

Description

Use FieldContent and FieldDescription for helper text.

By clicking this checkbox, you agree to the terms and conditions.

<FieldGroup Class="mx-auto w-72">
    <Field Orientation="FieldOrientation.Horizontal">
        <Checkbox id="terms-checkbox-desc" Name="terms-checkbox-desc" Checked="true" />
        <FieldContent>
            <FieldLabel for="terms-checkbox-desc">Accept terms and conditions</FieldLabel>
            <FieldDescription>By clicking this checkbox, you agree to the terms and conditions.</FieldDescription>
        </FieldContent>
    </Field>
</FieldGroup>

Disabled

Use the Disabled parameter to prevent interaction and add the data-disabled attribute to the <Field> component for disabled styles.

<FieldGroup Class="mx-auto w-56">
    <Field Orientation="FieldOrientation.Horizontal" data-disabled>
        <Checkbox id="toggle-checkbox-disabled" Name="toggle-checkbox-disabled" Disabled="true" />
        <FieldLabel for="toggle-checkbox-disabled">Enable notifications</FieldLabel>
    </Field>
</FieldGroup>

Group

Use multiple fields to create a checkbox list.

Show these items on the desktop:

Select the items you want to show on the desktop.

<FieldSet>
    <FieldLegend Variant="FieldLegendVariant.Label">Show these items on the desktop:</FieldLegend>
    <FieldDescription>Select the items you want to show on the desktop.</FieldDescription>

Table

Name Email Role
Sarah Chen sarah.chen@example.com Admin
Marcus Rodriguez marcus.rodriguez@example.com User
Priya Patel priya.patel@example.com User
David Kim david.kim@example.com Editor
<Table>
    <TableHeader>
        <TableRow>

RTL

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

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

بالنقر على هذا المربع، فإنك توافق على الشروط.

<FieldGroup Class="max-w-sm">
    <Field Orientation="FieldOrientation.Horizontal">
        <Checkbox id="checkbox-rtl-terms" Name="terms-checkbox" />

API Reference

Checkbox

ParameterTypeDefault
Render RenderFragment<CheckboxRenderProps>? -
Checked bool false
CheckedChanged EventCallback<bool> -
OnCheckedChange EventCallback<ValueChangeEventArgs<bool>> -
Indeterminate bool false
Disabled bool false
ReadOnly bool false
Required bool false
Name string? -
Value string? -
UncheckedValue string? -
InputId string? -
Parent bool false
Class string? -

Other attributes are passed to the element it renders.