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

Method _handleInputClick

src/material/checkbox/checkbox.ts:416–447  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

414 }
415
416 protected _handleInputClick() {
417 const clickAction = this._options?.clickAction;
418
419 // If resetIndeterminate is false, and the current state is indeterminate, do nothing on click
420 if (!this.disabled && clickAction !== 'noop') {
421 // When user manually click on the checkbox, `indeterminate` is set to false.
422 if (this.indeterminate && clickAction !== 'check') {
423 Promise.resolve().then(() => {
424 this._indeterminate.set(false);
425 this.indeterminateChange.emit(false);
426 });
427 }
428
429 this._checked = !this._checked;
430 this._transitionCheckState(
431 this._checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked,
432 );
433
434 // Emit our custom change event if the native input emitted one.
435 // It is important to only emit it, if the native input triggered one, because
436 // we don't want to trigger a change event, when the `checked` variable changes for example.
437 this._emitChangeEvent();
438 } else if (
439 (this.disabled && this.disabledInteractive) ||
440 (!this.disabled && clickAction === 'noop')
441 ) {
442 // Reset native input when clicked with noop. The native checkbox becomes checked after
443 // click, reset it to be align with `checked` value of `mat-checkbox`.
444 this._inputElement.nativeElement.checked = this.checked;
445 this._inputElement.nativeElement.indeterminate = this.indeterminate;
446 }
447 }
448
449 _onInteractionEvent(event: Event) {
450 // We always have to stop propagation on the change event.

Callers 1

_onInputClickMethod · 0.95

Calls 4

_transitionCheckStateMethod · 0.95
_emitChangeEventMethod · 0.95
resolveMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected