The Checkbox component allows users to select one or more options from a set of choices with support for indeterminate state and custom labels.
Basic usage
<flx-checkbox
label="Accept terms and conditions"
[(ngModel)]="accepted">
</flx-checkbox>
Properties
Label text displayed next to the checkbox
Whether the checkbox is checked
Whether the checkbox is in indeterminate state (partially checked)
Marks the checkbox as required
Value associated with the checkbox (useful in groups)
Events
Emitted when the checked state changes
Examples
Single checkbox
Checkbox group
Indeterminate state
Reactive forms
<flx-checkbox
label="Subscribe to newsletter"
[(ngModel)]="subscribed">
</flx-checkbox>
<flx-checkbox
label="Remember me"
[(ngModel)]="rememberMe">
</flx-checkbox>
<div class="checkbox-group">
<h3>Select features</h3>
<flx-checkbox
label="Email notifications"
[(ngModel)]="features.email">
</flx-checkbox>
<flx-checkbox
label="SMS notifications"
[(ngModel)]="features.sms">
</flx-checkbox>
<flx-checkbox
label="Push notifications"
[(ngModel)]="features.push">
</flx-checkbox>
</div>
export class NotificationSettings {
features = {
email: false,
sms: false,
push: true
};
}
<flx-checkbox
label="Select all"
[checked]="allSelected"
[indeterminate]="someSelected"
(checkedChange)="toggleAll($event)">
</flx-checkbox>
<div class="checkbox-list">
<flx-checkbox
*ngFor="let item of items"
[label]="item.name"
[(ngModel)]="item.selected"
(checkedChange)="updateSelectAll()">
</flx-checkbox>
</div>
export class SelectableList {
items = [
{ name: 'Item 1', selected: false },
{ name: 'Item 2', selected: false },
{ name: 'Item 3', selected: false }
];
get allSelected(): boolean {
return this.items.every(item => item.selected);
}
get someSelected(): boolean {
const selected = this.items.filter(item => item.selected).length;
return selected > 0 && selected < this.items.length;
}
toggleAll(checked: boolean) {
this.items.forEach(item => item.selected = checked);
}
updateSelectAll() {
// Automatically updates based on getters
}
}
<form [formGroup]="preferencesForm">
<flx-checkbox
label="Marketing emails"
formControlName="marketingEmails">
</flx-checkbox>
<flx-checkbox
label="Product updates"
formControlName="productUpdates">
</flx-checkbox>
<flx-checkbox
label="Terms acceptance"
formControlName="acceptTerms"
[required]="true"
[error]="acceptTermsControl.invalid && acceptTermsControl.touched">
</flx-checkbox>
</form>
import { FormBuilder, Validators } from '@angular/forms';
export class PreferencesComponent {
preferencesForm = this.fb.group({
marketingEmails: [false],
productUpdates: [true],
acceptTerms: [false, Validators.requiredTrue]
});
get acceptTermsControl() { return this.preferencesForm.get('acceptTerms')!; }
constructor(private fb: FormBuilder) {}
}
Styling
flx-checkbox {
--flx-checkbox-size: 18px;
--flx-checkbox-border-radius: 3px;
--flx-checkbox-border-color: #d1d5db;
--flx-checkbox-checked-background: #3b82f6;
--flx-checkbox-checked-border-color: #3b82f6;
--flx-checkbox-checkmark-color: #ffffff;
--flx-checkbox-disabled-opacity: 0.5;
--flx-checkbox-error-border-color: #ef4444;
}
Accessibility
The Checkbox component provides full keyboard and screen reader support:
- Space key toggles the checkbox
aria-checked reflects the current state
aria-required for required checkboxes
- Proper label association
- Radio - Single selection from options
- Switch - Toggle switch for binary choices