@@ -14,36 +14,53 @@ import {
14
14
OnInit ,
15
15
TemplateRef ,
16
16
ViewEncapsulation ,
17
- numberAttribute
17
+ numberAttribute ,
18
+ inject ,
19
+ Output ,
20
+ EventEmitter ,
21
+ booleanAttribute
18
22
} from '@angular/core' ;
19
23
20
24
import { NzHighlightModule } from 'ng-zorro-antd/core/highlight' ;
21
25
import { NzOutletModule } from 'ng-zorro-antd/core/outlet' ;
26
+ import { NzTreeNode } from 'ng-zorro-antd/core/tree' ;
22
27
import { NzIconModule } from 'ng-zorro-antd/icon' ;
23
28
24
29
import { NzCascaderOption } from './typings' ;
25
30
26
31
@Component ( {
27
- changeDetection : ChangeDetectionStrategy . OnPush ,
28
- encapsulation : ViewEncapsulation . None ,
32
+ standalone : true ,
29
33
selector : '[nz-cascader-option]' ,
30
34
exportAs : 'nzCascaderOption' ,
35
+ imports : [ NgTemplateOutlet , NzHighlightModule , NzIconModule , NzOutletModule ] ,
31
36
template : `
37
+ @if (checkable) {
38
+ <span
39
+ class="ant-cascader-checkbox"
40
+ [class.ant-cascader-checkbox-checked]="checked"
41
+ [class.ant-cascader-checkbox-indeterminate]="halfChecked"
42
+ [class.ant-cascader-checkbox-disabled]="disabled"
43
+ (click)="onCheckboxClick($event)"
44
+ >
45
+ <span class="ant-cascader-checkbox-inner"></span>
46
+ </span>
47
+ }
48
+
32
49
@if (optionTemplate) {
33
50
<ng-template
34
51
[ngTemplateOutlet]="optionTemplate"
35
- [ngTemplateOutletContext]="{ $implicit: option , index: columnIndex }"
52
+ [ngTemplateOutletContext]="{ $implicit: node.origin , index: columnIndex }"
36
53
/>
37
54
} @else {
38
55
<div
39
56
class="ant-cascader-menu-item-content"
40
- [innerHTML]="optionLabel | nzHighlight: highlightText : 'g' : 'ant-cascader-menu-item-keyword'"
57
+ [innerHTML]="node.title | nzHighlight: highlightText : 'g' : 'ant-cascader-menu-item-keyword'"
41
58
></div>
42
59
}
43
60
44
- @if (!option .isLeaf || option .children?.length || option.loading ) {
61
+ @if (!node .isLeaf || node .children?.length || node.isLoading ) {
45
62
<div class="ant-cascader-menu-item-expand-icon">
46
- @if (option.loading ) {
63
+ @if (node.isLoading ) {
47
64
<span nz-icon nzType="loading"></span>
48
65
} @else {
49
66
<ng-container *nzStringTemplateOutlet="expandIcon">
@@ -55,32 +72,31 @@ import { NzCascaderOption } from './typings';
55
72
` ,
56
73
host : {
57
74
class : 'ant-cascader-menu-item ant-cascader-menu-item-expanded' ,
58
- '[attr.title]' : 'option .title || optionLabel ' ,
75
+ '[attr.title]' : 'node .title' ,
59
76
'[class.ant-cascader-menu-item-active]' : 'activated' ,
60
- '[class.ant-cascader-menu-item-expand]' : '!option .isLeaf' ,
61
- '[class.ant-cascader-menu-item-disabled]' : 'option.disabled '
77
+ '[class.ant-cascader-menu-item-expand]' : '!node .isLeaf' ,
78
+ '[class.ant-cascader-menu-item-disabled]' : 'node.isDisabled '
62
79
} ,
63
- imports : [ NgTemplateOutlet , NzHighlightModule , NzIconModule , NzOutletModule ] ,
64
- standalone : true
80
+ changeDetection : ChangeDetectionStrategy . OnPush ,
81
+ encapsulation : ViewEncapsulation . None
65
82
} )
66
83
export class NzCascaderOptionComponent implements OnInit {
67
84
@Input ( ) optionTemplate : TemplateRef < NzCascaderOption > | null = null ;
68
- @Input ( ) option ! : NzCascaderOption ;
85
+ @Input ( ) node ! : NzTreeNode ;
69
86
@Input ( ) activated = false ;
70
87
@Input ( ) highlightText ! : string ;
71
88
@Input ( ) nzLabelProperty = 'label' ;
72
89
@Input ( { transform : numberAttribute } ) columnIndex ! : number ;
73
90
@Input ( ) expandIcon : string | TemplateRef < void > = '' ;
74
91
@Input ( ) dir : Direction = 'ltr' ;
92
+ @Input ( { transform : booleanAttribute } ) checkable ?: boolean = false ;
75
93
76
- readonly nativeElement : HTMLElement ;
94
+ @Output ( ) readonly check = new EventEmitter < void > ( ) ;
95
+
96
+ public readonly nativeElement : HTMLElement = inject ( ElementRef ) . nativeElement ;
97
+
98
+ constructor ( private cdr : ChangeDetectorRef ) { }
77
99
78
- constructor (
79
- private cdr : ChangeDetectorRef ,
80
- elementRef : ElementRef
81
- ) {
82
- this . nativeElement = elementRef . nativeElement ;
83
- }
84
100
ngOnInit ( ) : void {
85
101
if ( this . expandIcon === '' && this . dir === 'rtl' ) {
86
102
this . expandIcon = 'left' ;
@@ -89,11 +105,28 @@ export class NzCascaderOptionComponent implements OnInit {
89
105
}
90
106
}
91
107
92
- get optionLabel ( ) : string {
93
- return this . option [ this . nzLabelProperty ] ;
108
+ get checked ( ) : boolean {
109
+ return this . node . isChecked ;
110
+ }
111
+
112
+ get halfChecked ( ) : boolean {
113
+ return this . node . isHalfChecked ;
114
+ }
115
+
116
+ get disabled ( ) : boolean {
117
+ return this . node . isDisabled || this . node . isDisableCheckbox ;
94
118
}
95
119
96
120
markForCheck ( ) : void {
97
121
this . cdr . markForCheck ( ) ;
98
122
}
123
+
124
+ onCheckboxClick ( event : MouseEvent ) : void {
125
+ event . preventDefault ( ) ;
126
+ event . stopPropagation ( ) ;
127
+ if ( ! this . checkable ) {
128
+ return ;
129
+ }
130
+ this . check . emit ( ) ;
131
+ }
99
132
}
0 commit comments