Skip to content

Commit

Permalink
refactor(module:checkbox): implement new control flow (#8304)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoss54 authored Dec 21, 2023
1 parent dbe5b0d commit 62fc752
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions components/checkbox/checkbox-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import { FocusMonitor } from '@angular/cdk/a11y';
import { Direction, Directionality } from '@angular/cdk/bidi';
import { NgForOf } from '@angular/common';
import {
ChangeDetectorRef,
Component,
Expand Down Expand Up @@ -39,16 +38,17 @@ export interface NzCheckBoxOptionInterface {
preserveWhitespaces: false,
encapsulation: ViewEncapsulation.None,
template: `
<label
nz-checkbox
class="ant-checkbox-group-item"
*ngFor="let o of options; trackBy: trackByOption"
[nzDisabled]="o.disabled || nzDisabled"
[nzChecked]="o.checked!"
(nzCheckedChange)="onCheckedChange(o, $event)"
>
<span>{{ o.label }}</span>
</label>
@for (option of options; track option.value) {
<label
nz-checkbox
class="ant-checkbox-group-item"
[nzDisabled]="option.disabled || nzDisabled"
[nzChecked]="option.checked!"
(nzCheckedChange)="onCheckedChange(option, $event)"
>
<span>{{ option.label }}</span>
</label>
}
`,
providers: [
{
Expand All @@ -61,7 +61,7 @@ export interface NzCheckBoxOptionInterface {
class: 'ant-checkbox-group',
'[class.ant-checkbox-group-rtl]': `dir === 'rtl'`
},
imports: [NgForOf, NzCheckboxComponent],
imports: [NzCheckboxComponent],
standalone: true
})
export class NzCheckboxGroupComponent implements ControlValueAccessor, OnInit, OnDestroy {
Expand All @@ -77,10 +77,6 @@ export class NzCheckboxGroupComponent implements ControlValueAccessor, OnInit, O
private destroy$ = new Subject<void>();
private isNzDisableFirstChange: boolean = true;

trackByOption(_: number, option: NzCheckBoxOptionInterface): string {
return option.value;
}

onCheckedChange(option: NzCheckBoxOptionInterface, checked: boolean): void {
option.checked = checked;
this.onChange(this.options);
Expand Down

0 comments on commit 62fc752

Please sign in to comment.