<commit_before>import {
  AfterViewInit,
  ChangeDetectionStrategy,
  ChangeDetectorRef,
  Component,
  ElementRef,
  EventEmitter,
  forwardRef,
  HostBinding,
  Input,
  OnDestroy,
  Output,
  ViewChild,
  ViewEncapsulation
} from '@angular/core';
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';
import { isBrowser, toBoolean } from '@angular-mdc/web/common';
import { MdcRipple } from '@angular-mdc/web/ripple';
import { MdcFormFieldControl } from '@angular-mdc/web/form-field';

import { getCorrectEventName } from '@material/animation';

import { MDCCheckboxAdapter } from '@material/checkbox/adapter';
import { MDCCheckboxFoundation } from '@material/checkbox';

let nextUniqueId = 0;

/** Change event object emitted by MdcCheckbox. */
export class MdcCheckboxChange {
  constructor(
    /** The source MdcCheckbox of the event. */
    public source: MdcCheckbox,
    /** The new `checked` value of the checkbox. */
    public checked: boolean) { }
}

export interface MdcIndeterminateChange {
  source: MdcCheckbox;
  indeterminate: boolean;
}

export const MDC_CHECKBOX_CONTROL_VALUE_ACCESSOR: any = {
  provide: NG_VALUE_ACCESSOR,
  useExisting: forwardRef(() => MdcCheckbox),
  multi: true
};

@Component({
  moduleId: module.id,
  selector: 'mdc-checkbox',
  exportAs: 'mdcCheckbox',
  host: {
    '[id]': 'id',
  },
  template: `
  <input type="checkbox"
    #input
    class="mdc-checkbox__native-control"
    [id]="inputId"
    [name]="name"
    [tabIndex]="tabIndex"
    [attr.aria-label]="ariaLabel"
    [attr.aria-labelledby]="ariaLabelledby"
    [disabled]="disabled"
    [checked]="checked"
    [attr.value]="checked"
    [indeterminate]="indeterminate"
    (change)="onChange($event)"
    (click)="_onInputClick($event)"/>
  <div class="mdc-checkbox__background">
    <svg class="mdc-checkbox__checkmark"
      viewBox="0 0 24 24">
      <path class="mdc-checkbox__checkmark-path"
            fill="none"
            stroke="white"
            d="M1.73,12.91 8.1,19.28 22.79,4.59"></path>
    </svg>
    <div class="mdc-checkbox__mixedmark"></div>
  </div>
  `,
  providers: [
    MDC_CHECKBOX_CONTROL_VALUE_ACCESSOR,
    MdcRipple,
    [{ provide: MdcFormFieldControl, useExisting: MdcCheckbox }]
  ],
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class MdcCheckbox implements AfterViewInit, ControlValueAccessor, OnDestroy, MdcFormFieldControl<any> {
  readonly componentInstance = MdcCheckbox;

  private _mdcAdapter: MDCCheckboxAdapter = {
    addClass: (className: string) => this._getHostElement().classList.add(className),
    removeClass: (className: string) => this._getHostElement().classList.remove(className),
    setNativeControlAttr: (attr: string, value: string) => this._getInputElement().setAttribute(attr, value),
    removeNativeControlAttr: (attr: string) => this._getInputElement().removeAttribute(attr),
    registerAnimationEndHandler: (handler: EventListener) => {
      if (isBrowser()) {
        this._getHostElement().addEventListener(getCorrectEventName(window, 'animationend'), handler);
      }
    },
    deregisterAnimationEndHandler: (handler: EventListener) => {
      if (isBrowser()) {
        this._getHostElement().removeEventListener(getCorrectEventName(window, 'animationend'), handler);
      }
    },
    registerChangeHandler: (handler: EventListener) => this._getHostElement().addEventListener('change', handler),
    deregisterChangeHandler: (handler: EventListener) => this._getHostElement().removeEventListener('change', handler),
    getNativeControl: () => this._getInputElement(),
    forceLayout: () => this._getHostElement().offsetWidth,
    isAttachedToDOM: () => !!this.inputEl
  };

  private _foundation: {
    init(): void,
    destroy(): void,
    isChecked(): boolean,
    setChecked(checked: any): void,
    setDisabled(disabled: boolean): void,
    isDisabled(): boolean,
    getValue(): any,
    setValue(value: any): void,
    isIndeterminate(): boolean,
    setIndeterminate(indeterminate: boolean): void
  } = new MDCCheckboxFoundation(this._mdcAdapter);

  private _uniqueId: string = `mdc-checkbox-${++nextUniqueId}`;

  @Input() id: string = this._uniqueId;
  get inputId(): string { return `${this.id || this._uniqueId}-input`; }

  @Input() name: string | null = null;

  @Input()
  get checked(): boolean { return this._checked; }
  set checked(value: boolean) {<commit_msg>fix(checkbox): Should listen on input element for change (#1233)<commit_after>import {
  AfterViewInit,
  ChangeDetectionStrategy,
  ChangeDetectorRef,
  Component,
  ElementRef,
  EventEmitter,
  forwardRef,
  HostBinding,
  Input,
  OnDestroy,
  Output,
  ViewChild,
  ViewEncapsulation
} from '@angular/core';
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';
import { isBrowser, toBoolean } from '@angular-mdc/web/common';
import { MdcRipple } from '@angular-mdc/web/ripple';
import { MdcFormFieldControl } from '@angular-mdc/web/form-field';

import { getCorrectEventName } from '@material/animation';

import { MDCCheckboxAdapter } from '@material/checkbox/adapter';
import { MDCCheckboxFoundation } from '@material/checkbox';

let nextUniqueId = 0;

/** Change event object emitted by MdcCheckbox. */
export class MdcCheckboxChange {
  constructor(
    /** The source MdcCheckbox of the event. */
    public source: MdcCheckbox,
    /** The new `checked` value of the checkbox. */
    public checked: boolean) { }
}

export interface MdcIndeterminateChange {
  source: MdcCheckbox;
  indeterminate: boolean;
}

export const MDC_CHECKBOX_CONTROL_VALUE_ACCESSOR: any = {
  provide: NG_VALUE_ACCESSOR,
  useExisting: forwardRef(() => MdcCheckbox),
  multi: true
};

@Component({
  moduleId: module.id,
  selector: 'mdc-checkbox',
  exportAs: 'mdcCheckbox',
  host: {
    '[id]': 'id',
  },
  template: `
  <input type="checkbox"
    #input
    class="mdc-checkbox__native-control"
    [id]="inputId"
    [name]="name"
    [tabIndex]="tabIndex"
    [attr.aria-label]="ariaLabel"
    [attr.aria-labelledby]="ariaLabelledby"
    [disabled]="disabled"
    [checked]="checked"
    [attr.value]="checked"
    [indeterminate]="indeterminate"
    (change)="onChange($event)"
    (click)="_onInputClick($event)"/>
  <div class="mdc-checkbox__background">
    <svg class="mdc-checkbox__checkmark"
      viewBox="0 0 24 24">
      <path class="mdc-checkbox__checkmark-path"
            fill="none"
            stroke="white"
            d="M1.73,12.91 8.1,19.28 22.79,4.59"></path>
    </svg>
    <div class="mdc-checkbox__mixedmark"></div>
  </div>
  `,
  providers: [
    MDC_CHECKBOX_CONTROL_VALUE_ACCESSOR,
    MdcRipple,
    [{ provide: MdcFormFieldControl, useExisting: MdcCheckbox }]
  ],
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class MdcCheckbox implements AfterViewInit, ControlValueAccessor, OnDestroy, MdcFormFieldControl<any> {
  readonly componentInstance = MdcCheckbox;

  private _mdcAdapter: MDCCheckboxAdapter = {
    addClass: (className: string) => this._getHostElement().classList.add(className),
    removeClass: (className: string) => this._getHostElement().classList.remove(className),
    setNativeControlAttr: (attr: string, value: string) => this._getInputElement().setAttribute(attr, value),
    removeNativeControlAttr: (attr: string) => this._getInputElement().removeAttribute(attr),
    registerAnimationEndHandler: (handler: EventListener) => {
      if (isBrowser()) {
        this._getHostElement().addEventListener(getCorrectEventName(window, 'animationend'), handler);
      }
    },
    deregisterAnimationEndHandler: (handler: EventListener) => {
      if (isBrowser()) {
        this._getHostElement().removeEventListener(getCorrectEventName(window, 'animationend'), handler);
      }
    },
    registerChangeHandler: (handler: EventListener) => this._getInputElement().addEventListener('change', handler),
    deregisterChangeHandler: (handler: EventListener) => this._getInputElement().removeEventListener('change', handler),
    getNativeControl: () => this._getInputElement(),
    forceLayout: () => this._getHostElement().offsetWidth,
    isAttachedToDOM: () => !!this.inputEl
  };

  private _foundation: {
    init(): void,
    destroy(): void,
    isChecked(): boolean,
    setChecked(checked: any): void,
    setDisabled(disabled: boolean): void,
    isDisabled(): boolean,
    getValue(): any,
    setValue(value: any): void,
    isIndeterminate(): boolean,
    setIndeterminate(indeterminate: boolean): void
  } = new MDCCheckboxFoundation(this._mdcAdapter);

  private _uniqueId: string = `mdc-checkbox-${++nextUniqueId}`;

  @Input() id: string = this._uniqueId;
  get inputId(): string { return `${this.id || this._uniqueId}-input`; }

  @Input() name: string | null = null;

  @Input()
  get checked(): boolean { return this._checked; }
  set checked(value: boolean) {
{'fraction_non_alphanumeric': 0.13769978763831453, 'fraction_numerical': 0.006482619872582989, 'mean_word_length': 4.459426479560708, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1183055', 'n_tokens_mistral': 2826, 'n_tokens_neox': 2751, 'n_words': 554}