Skip to content

Commit 1491fb3

Browse files
feat(module:checkbox): support standalone component (#8269)
1 parent 7325781 commit 1491fb3

File tree

6 files changed

+63
-61
lines changed

6 files changed

+63
-61
lines changed

components/checkbox/checkbox-group.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { FocusMonitor } from '@angular/cdk/a11y';
77
import { Direction, Directionality } from '@angular/cdk/bidi';
8+
import { NgForOf } from '@angular/common';
89
import {
910
ChangeDetectorRef,
1011
Component,
@@ -23,6 +24,8 @@ import { takeUntil } from 'rxjs/operators';
2324
import { BooleanInput, OnChangeType, OnTouchedType } from 'ng-zorro-antd/core/types';
2425
import { InputBoolean } from 'ng-zorro-antd/core/util';
2526

27+
import { NzCheckboxComponent } from './checkbox.component';
28+
2629
export interface NzCheckBoxOptionInterface {
2730
label: string;
2831
value: string;
@@ -57,7 +60,9 @@ export interface NzCheckBoxOptionInterface {
5760
host: {
5861
class: 'ant-checkbox-group',
5962
'[class.ant-checkbox-group-rtl]': `dir === 'rtl'`
60-
}
63+
},
64+
imports: [NgForOf, NzCheckboxComponent],
65+
standalone: true
6166
})
6267
export class NzCheckboxGroupComponent implements ControlValueAccessor, OnInit, OnDestroy {
6368
static ngAcceptInputType_nzDisabled: BooleanInput;

components/checkbox/checkbox-wrapper.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import { NzCheckboxComponent } from './checkbox.component';
1818
template: ` <ng-content></ng-content> `,
1919
host: {
2020
class: 'ant-checkbox-group'
21-
}
21+
},
22+
standalone: true
2223
})
2324
export class NzCheckboxWrapperComponent {
2425
@Output() readonly nzOnChange = new EventEmitter<NzSafeAny[]>();

components/checkbox/checkbox.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
ViewChild,
2323
ViewEncapsulation
2424
} from '@angular/core';
25-
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
25+
import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
2626
import { fromEvent, Subject } from 'rxjs';
2727
import { takeUntil } from 'rxjs/operators';
2828

@@ -72,7 +72,9 @@ import { NzCheckboxWrapperComponent } from './checkbox-wrapper.component';
7272
'[class.ant-checkbox-wrapper-in-form-item]': '!!nzFormStatusService',
7373
'[class.ant-checkbox-wrapper-checked]': 'nzChecked',
7474
'[class.ant-checkbox-rtl]': `dir === 'rtl'`
75-
}
75+
},
76+
imports: [FormsModule],
77+
standalone: true
7678
})
7779
export class NzCheckboxComponent implements OnInit, ControlValueAccessor, OnDestroy, AfterViewInit {
7880
static ngAcceptInputType_nzAutoFocus: BooleanInput;

components/checkbox/checkbox.module.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@
33
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
44
*/
55

6-
import { A11yModule } from '@angular/cdk/a11y';
7-
import { BidiModule } from '@angular/cdk/bidi';
8-
import { CommonModule } from '@angular/common';
96
import { NgModule } from '@angular/core';
10-
import { FormsModule } from '@angular/forms';
117

128
import { NzCheckboxGroupComponent } from './checkbox-group.component';
139
import { NzCheckboxWrapperComponent } from './checkbox-wrapper.component';
1410
import { NzCheckboxComponent } from './checkbox.component';
1511

1612
@NgModule({
17-
imports: [BidiModule, CommonModule, FormsModule, A11yModule],
18-
declarations: [NzCheckboxComponent, NzCheckboxGroupComponent, NzCheckboxWrapperComponent],
13+
imports: [NzCheckboxComponent, NzCheckboxGroupComponent, NzCheckboxWrapperComponent],
1914
exports: [NzCheckboxComponent, NzCheckboxGroupComponent, NzCheckboxWrapperComponent]
2015
})
2116
export class NzCheckboxModule {}

components/checkbox/doc/index.en-US.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,37 @@ import { NzCheckboxModule } from 'ng-zorro-antd/checkbox';
1818

1919
## API
2020

21-
### [nz-checkbox]
21+
### [nz-checkbox]:standalone
2222

23-
| Property | Description | Type | Default |
24-
| -------- | ----------- | ---- | ------- |
25-
| `[nzId]` | input id attribute inside the component| `string` | - |
26-
| `[nzAutoFocus]` | get focus when component mounted | `boolean` | `false` |
27-
| `[nzDisabled]` | Disable checkbox | `boolean` | `false` |
28-
| `[ngModel]` | Specifies whether the checkbox is selected, double binding | `boolean` | `false` |
29-
| `[nzIndeterminate]` | set the status of indeterminate,only affect the style | `boolean` | `false` |
30-
| `[nzValue]` | use for the callback of `nz-checkbox-wrapper` | `any` | - |
31-
| `(ngModelChange)` | The callback function that is triggered when the state changes. | `EventEmitter<boolean>` | - |
23+
| Property | Description | Type | Default |
24+
| ------------------- | --------------------------------------------------------------- | ----------------------- | ------- |
25+
| `[nzId]` | input id attribute inside the component | `string` | - |
26+
| `[nzAutoFocus]` | get focus when component mounted | `boolean` | `false` |
27+
| `[nzDisabled]` | Disable checkbox | `boolean` | `false` |
28+
| `[ngModel]` | Specifies whether the checkbox is selected, double binding | `boolean` | `false` |
29+
| `[nzIndeterminate]` | set the status of indeterminate,only affect the style | `boolean` | `false` |
30+
| `[nzValue]` | use for the callback of `nz-checkbox-wrapper` | `any` | - |
31+
| `(ngModelChange)` | The callback function that is triggered when the state changes. | `EventEmitter<boolean>` | - |
3232

33-
### nz-checkbox-group
33+
### nz-checkbox-group:standalone
3434

35-
| Property | Description | Type | Default |
36-
| -------- | ----------- | ---- | ------- |
37-
| `[ngModel]` | Specifies options, double binding | `Array<{ label: string; value: string; checked?: boolean; }>` | `[]` |
38-
| `[nzDisabled]` | Disable all checkboxes | `boolean` | `false` |
39-
| `(ngModelChange)` | The callback function that is triggered when the state changes. | `EventEmitter<Array<{ label: string; value: string; checked?: boolean; }>>` | - |
35+
| Property | Description | Type | Default |
36+
| ----------------- | --------------------------------------------------------------- | --------------------------------------------------------------------------- | ------- |
37+
| `[ngModel]` | Specifies options, double binding | `Array<{ label: string; value: string; checked?: boolean; }>` | `[]` |
38+
| `[nzDisabled]` | Disable all checkboxes | `boolean` | `false` |
39+
| `(ngModelChange)` | The callback function that is triggered when the state changes. | `EventEmitter<Array<{ label: string; value: string; checked?: boolean; }>>` | - |
4040

41-
### nz-checkbox-wrapper
41+
### nz-checkbox-wrapper:standalone
4242

43-
| Property | Description | Type | Default |
44-
| -------- | ----------- | ---- | ------- |
45-
| `(nzOnChange)` | The callback function that is triggered when the state changes. | `EventEmitter<any[]>` | - |
43+
| Property | Description | Type | Default |
44+
| -------------- | --------------------------------------------------------------- | --------------------- | ------- |
45+
| `(nzOnChange)` | The callback function that is triggered when the state changes. | `EventEmitter<any[]>` | - |
4646

4747
## Methods
4848

49-
### [nz-checkbox]
49+
### [nz-checkbox]:standalone
5050

51-
| Name | Description |
52-
| ---- | ----------- |
53-
| focus() | get focus |
54-
| blur() | remove focus |
51+
| Name | Description |
52+
| ------- | ------------ |
53+
| focus() | get focus |
54+
| blur() | remove focus |

components/checkbox/doc/index.zh-CN.md

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,39 @@ import { NzCheckboxModule } from 'ng-zorro-antd/checkbox';
1919

2020
## API
2121

22-
### [nz-checkbox]
22+
### [nz-checkbox]:standalone
2323

24-
| 参数 | 说明 | 类型 | 默认值 |
25-
| --- | --- | --- | --- |
26-
| `[nzId]` | 组件内部 input 的 id 值 | `string` | - |
27-
| `[nzAutoFocus]` | 自动获取焦点 | `boolean` | `false` |
28-
| `[nzDisabled]` | 设定 disable 状态 | `boolean` | `false` |
29-
| `[ngModel]` | 指定当前是否选中,可双向绑定 | `boolean` | `false` |
30-
| `[nzIndeterminate]` | 设置 indeterminate 状态,只负责样式控制 | `boolean` | `false` |
31-
| `[nzValue]` | 仅与 `nz-checkbox-wrapper` 的选中回调配合使用 | `any` | - |
32-
| `(ngModelChange)` | 选中变化时回调 | `EventEmitter<boolean>` | - |
24+
| 参数 | 说明 | 类型 | 默认值 |
25+
| ------------------- | --------------------------------------------- | ----------------------- | ------- |
26+
| `[nzId]` | 组件内部 input 的 id 值 | `string` | - |
27+
| `[nzAutoFocus]` | 自动获取焦点 | `boolean` | `false` |
28+
| `[nzDisabled]` | 设定 disable 状态 | `boolean` | `false` |
29+
| `[ngModel]` | 指定当前是否选中,可双向绑定 | `boolean` | `false` |
30+
| `[nzIndeterminate]` | 设置 indeterminate 状态,只负责样式控制 | `boolean` | `false` |
31+
| `[nzValue]` | 仅与 `nz-checkbox-wrapper` 的选中回调配合使用 | `any` | - |
32+
| `(ngModelChange)` | 选中变化时回调 | `EventEmitter<boolean>` | - |
3333

34-
### nz-checkbox-group
34+
### nz-checkbox-group:standalone
3535

36-
| 参数 | 说明 | 类型 | 默认值 |
37-
| --- | --- | --- | --- |
38-
| `[ngModel]` | 指定可选项,可双向绑定 | `Array<{ label: string; value: string; checked?: boolean; }>` | `[]` |
39-
| `[nzDisabled]` | 设定全部 checkbox disable 状态 | `boolean` | `false` |
40-
| `(ngModelChange)` | 选中数据变化时的回调 | `EventEmitter<Array<{ label: string; value: string; checked?: boolean; }>>` | - |
36+
| 参数 | 说明 | 类型 | 默认值 |
37+
| ----------------- | ------------------------------ | --------------------------------------------------------------------------- | ------- |
38+
| `[ngModel]` | 指定可选项,可双向绑定 | `Array<{ label: string; value: string; checked?: boolean; }>` | `[]` |
39+
| `[nzDisabled]` | 设定全部 checkbox disable 状态 | `boolean` | `false` |
40+
| `(ngModelChange)` | 选中数据变化时的回调 | `EventEmitter<Array<{ label: string; value: string; checked?: boolean; }>>` | - |
4141

42+
### nz-checkbox-wrapper:standalone
4243

43-
### nz-checkbox-wrapper
44-
45-
| 参数 | 说明 | 类型 | 默认值 |
46-
| --- | --- | --- | --- |
47-
| `(nzOnChange)` | 选中数据变化时的回调 | `EventEmitter<any[]>` | - |
44+
| 参数 | 说明 | 类型 | 默认值 |
45+
| -------------- | -------------------- | --------------------- | ------ |
46+
| `(nzOnChange)` | 选中数据变化时的回调 | `EventEmitter<any[]>` | - |
4847

4948
## 方法
5049

51-
### [nz-checkbox]
50+
### [nz-checkbox]:standalone
5251

53-
通过ViewChild或其他方式获得 `nz-checkbox` 实例
52+
通过 ViewChild 或其他方式获得 `nz-checkbox` 实例
5453

55-
| 名称 | 描述 |
56-
| ---- | ----------- |
54+
| 名称 | 描述 |
55+
| ------- | -------- |
5756
| focus() | 获取焦点 |
58-
| blur() | 移除焦点 |
57+
| blur() | 移除焦点 |

0 commit comments

Comments
 (0)