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

Method _handleInputClick

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

Source from the content-addressed store, hash-verified

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