MCPcopy Create free account
hub / github.com/angular/components / MatCheckbox

Class MatCheckbox

src/material/checkbox/checkbox.ts:108–540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106 imports: [MatRipple, _MatInternalFormField],
107})
108export class MatCheckbox
109 implements AfterViewInit, OnChanges, ControlValueAccessor, Validator, FocusableOption
110{
111 _elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
112 private _changeDetectorRef = inject(ChangeDetectorRef);
113 private _ngZone = inject(NgZone);
114 protected _animationsDisabled = _animationsDisabled();
115 private _options = inject<MatCheckboxDefaultOptions>(MAT_CHECKBOX_DEFAULT_OPTIONS, {
116 optional: true,
117 });
118
119 /** Focuses the checkbox. */
120 focus() {
121 this._inputElement.nativeElement.focus();
122 }
123
124 /** Creates the change event that will be emitted by the checkbox. */
125 protected _createChangeEvent(isChecked: boolean) {
126 const event = new MatCheckboxChange();
127 event.source = this;
128 event.checked = isChecked;
129 return event;
130 }
131
132 /** Gets the element on which to add the animation CSS classes. */
133 protected _getAnimationTargetElement() {
134 return this._inputElement?.nativeElement;
135 }
136
137 /** CSS classes to add when transitioning between the different checkbox states. */
138 protected _animationClasses = {
139 uncheckedToChecked: 'mdc-checkbox--anim-unchecked-checked',
140 uncheckedToIndeterminate: 'mdc-checkbox--anim-unchecked-indeterminate',
141 checkedToUnchecked: 'mdc-checkbox--anim-checked-unchecked',
142 checkedToIndeterminate: 'mdc-checkbox--anim-checked-indeterminate',
143 indeterminateToChecked: 'mdc-checkbox--anim-indeterminate-checked',
144 indeterminateToUnchecked: 'mdc-checkbox--anim-indeterminate-unchecked',
145 };
146
147 /**
148 * Attached to the aria-label attribute of the host element. In most cases, aria-labelledby will
149 * take precedence so this may be omitted.
150 */
151 @Input('aria-label') ariaLabel: string = '';
152
153 /**
154 * Users can specify the `aria-labelledby` attribute which will be forwarded to the input element
155 */
156 @Input('aria-labelledby') ariaLabelledby: string | null = null;
157
158 /** The 'aria-describedby' attribute is read after the element's label and field type. */
159 @Input('aria-describedby') ariaDescribedby!: string;
160
161 /**
162 * Users can specify the `aria-expanded` attribute which will be forwarded to the input element
163 */
164 @Input({alias: 'aria-expanded', transform: booleanAttribute}) ariaExpanded!: boolean;
165

Callers

nothing calls this directly

Calls 2

_animationsDisabledFunction · 0.90
signalFunction · 0.85

Tested by

no test coverage detected