import { KbqCheckboxModule } from '@koobiq/components/checkbox';

KbqCheckbox

componentCopy link to KbqCheckbox

A Koobiq checkbox component. Supports all of the functionality of an HTML5 checkbox, and exposes a similar API. A KbqCheckbox can be either checked, unchecked, indeterminate, or disabled. Note that all additional accessibility attributes are taken care of by the component, so there is no need to provide them yourself. However, if you want to omit a label and still have the checkbox be accessible, you may supply an [aria-label] input.

To show a validation error, put its text in a kbq-error inside the checkbox bound to a form control.

@Component({ selector: 'kbq-checkbox', exportAs: 'kbqCheckbox' })
class KbqCheckbox extends KbqColorDirective implements CanUpdateErrorState {
readonly errorStateMatcher = input<ErrorStateMatcher>();
readonly big = input<boolean>(false);
readonly id = input<string>(this.uniqueId);
readonly labelPosition = input<'before' | 'after'>('after');
readonly name = input<string | null>(null);
readonly value = input<string>();
readonly clickAction = input<KbqCheckboxClickAction>(
inject(KBQ_CHECKBOX_CLICK_ACTION, { optional: true }) || undefined
);
readonly required = input<boolean>(false);
checked = input<boolean | undefined>();
disabled = input<boolean | undefined>();
indeterminate = model<boolean | undefined>();
readonly color = input<T | null | undefined>();
readonly change = output<KbqCheckboxChange>();
readonly errorState: Signal<boolean>;
get colorClassName(): string;
updateErrorState(): void;
toggle(): void;
focus(): void;
setDefaultColor(color: T): void;
}
errorStateMatcherinputCopy link to errorStateMatcherErrorStateMatcher

An object used to control when the error state is shown.

biginputCopy link to bigboolean

Whether the checkbox uses the big size.

idinputCopy link to idstring

A unique id for the checkbox input. If none is supplied — or null is bound explicitly — it is auto-generated, so a read always yields the id the element actually carries.

labelPositioninputCopy link to labelPosition'before' | 'after'

Whether the label should appear after or before the checkbox. Defaults to 'after'

nameinputCopy link to namestring | null

Name value will be applied to the input element if present

valueinputCopy link to valuestring

The value attribute of the native input element

clickActioninputCopy link to clickActionKbqCheckboxClickAction

Defines the behavior when a user clicks on the checkbox.

requiredinputCopy link to requiredboolean

Whether the checkbox is required.

checkedinputCopy link to checkedboolean | undefined

Whether the checkbox is checked.

disabledinputCopy link to disabledboolean | undefined

Whether the checkbox is disabled.

indeterminatemodelCopy link to indeterminateboolean | undefined

Whether the checkbox is indeterminate. This is also known as "mixed" mode and can be used to represent a checkbox with three states, e.g. a checkbox that represents a nested list of checkable items. Note that whenever checkbox is manually clicked, indeterminate is immediately set to false.

colorinputCopy link to colorT | null | undefined

Color of the component. A value set in code holds until the input changes, and the default color is used while both are unset or falsy.

changeoutputCopy link to changeKbqCheckboxChange

Event emitted when the checkbox's checked value changes.

errorStateCopy link to errorStateSignal<boolean>

Whether the checkbox is in an error state.

colorClassNameCopy link to colorClassNamestring

current class name of color

updateErrorState()Copy link to updateErrorState()void

Updates the error state based on the error state matcher.

toggle()Copy link to toggle()void

Toggles the checked state of the checkbox.

focus()Copy link to focus()void

Focuses the checkbox.

setDefaultColor()Copy link to setDefaultColor()void

this color will be used as a default value. For example [color]="'' | false | undefined | null".

KbqCheckboxRequiredValidator

directiveCopy link to KbqCheckboxRequiredValidator

Validator for koobiq checkbox's required attribute in template-driven checkbox. Current CheckboxRequiredValidator only work with input type=checkbox and does not work with kbq-checkbox.

@Directive({
selector: 'kbq-checkbox[required][formControlName], kbq-checkbox[required][formControl], kbq-checkbox[required][ngModel]'
})
class KbqCheckboxRequiredValidator extends CheckboxRequiredValidator {
required: string | boolean;
}

KbqCheckboxChange

classCopy link to KbqCheckboxChange

Change event object emitted by KbqCheckbox.

class KbqCheckboxChange {
source: KbqCheckbox;
checked: boolean;
}
sourceCopy link to sourceKbqCheckbox

The source KbqCheckbox of the event.

checkedCopy link to checkedboolean

The new checked value of the checkbox.

KbqCheckboxClickAction

typeCopy link to KbqCheckboxClickAction

Checkbox click action when user click on input element. noop: Do not toggle checked or indeterminate. check: Only toggle checked status, ignore indeterminate. check-indeterminate: Toggle checked status, set indeterminate to false. Default behavior. undefined: Same as check-indeterminate.

type KbqCheckboxClickAction = KbqCheckableClickAction;

KBQ_CHECKBOX_CLICK_ACTION

constCopy link to KBQ_CHECKBOX_CLICK_ACTION

Injection token that can be used to specify the checkbox click behavior.

const KBQ_CHECKBOX_CLICK_ACTION: InjectionToken<KbqCheckboxClickAction>;

KBQ_CHECKBOX_REQUIRED_VALIDATOR

constCopy link to KBQ_CHECKBOX_REQUIRED_VALIDATOR
const KBQ_CHECKBOX_REQUIRED_VALIDATOR: Provider;
Suggestions for improvement
If you found a mistake or want to improve the article, create an issue on GitHub.