Skip to content

Commit

Permalink
Merge c8d1f46 into 2d77bc2
Browse files Browse the repository at this point in the history
  • Loading branch information
arturovt committed Mar 9, 2022
2 parents 2d77bc2 + c8d1f46 commit 7cd502c
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions components/tree-view/checkbox.ts
Expand Up @@ -3,8 +3,21 @@
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
EventEmitter,
Input,
NgZone,
OnInit,
Output
} from '@angular/core';
import { fromEvent } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

import { NzDestroyService } from 'ng-zorro-antd/core/services';
import { BooleanInput } from 'ng-zorro-antd/core/types';
import { InputBoolean } from 'ng-zorro-antd/core/util';

Expand All @@ -17,21 +30,37 @@ import { InputBoolean } from 'ng-zorro-antd/core/util';
class: 'ant-tree-checkbox',
'[class.ant-tree-checkbox-checked]': `nzChecked`,
'[class.ant-tree-checkbox-indeterminate]': `nzIndeterminate`,
'[class.ant-tree-checkbox-disabled]': `nzDisabled`,
'(click)': 'onClick($event)'
}
'[class.ant-tree-checkbox-disabled]': `nzDisabled`
},
providers: [NzDestroyService]
})
export class NzTreeNodeCheckboxComponent {
export class NzTreeNodeCheckboxComponent implements OnInit {
static ngAcceptInputType_nzDisabled: BooleanInput;

@Input() nzChecked?: boolean;
@Input() nzIndeterminate?: boolean;
@Input() @InputBoolean() nzDisabled?: boolean;
@Output() readonly nzClick = new EventEmitter<MouseEvent>();

onClick(e: MouseEvent): void {
if (!this.nzDisabled) {
this.nzClick.emit(e);
}
constructor(
private ngZone: NgZone,
private ref: ChangeDetectorRef,
private host: ElementRef<HTMLElement>,
private destroy$: NzDestroyService
) {}

ngOnInit(): void {
this.ngZone.runOutsideAngular(() =>
fromEvent<MouseEvent>(this.host.nativeElement, 'click')
.pipe(takeUntil(this.destroy$))
.subscribe((event: MouseEvent) => {
if (!this.nzDisabled && this.nzClick.observers.length) {
this.ngZone.run(() => {
this.nzClick.emit(event);
this.ref.markForCheck();
});
}
})
);
}
}

0 comments on commit 7cd502c

Please sign in to comment.