From 573fbb9a4031f51b3613d02188374a7171b9ca4e Mon Sep 17 00:00:00 2001 From: Kenrick Tandrian <60643640+KenTandrian@users.noreply.github.com> Date: Sat, 14 Mar 2026 15:16:46 +0700 Subject: [PATCH] Task/improve type safety of toggle component (#6533) * Improve type safety --- libs/ui/src/lib/toggle/toggle.component.html | 7 +++-- libs/ui/src/lib/toggle/toggle.component.ts | 32 +++++++++++--------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/libs/ui/src/lib/toggle/toggle.component.html b/libs/ui/src/lib/toggle/toggle.component.html index ac2256daa..d6271ef58 100644 --- a/libs/ui/src/lib/toggle/toggle.component.html +++ b/libs/ui/src/lib/toggle/toggle.component.html @@ -3,13 +3,14 @@ [formControl]="optionFormControl" (change)="onValueChange()" > - @for (option of options; track option) { + @for (option of options(); track option) { {{ option.label }}(); + public readonly isLoading = input(false); + public readonly options = input([]); - @Output() valueChange = new EventEmitter>(); + protected readonly optionFormControl = new FormControl(null); + protected readonly valueChange = output>(); - public optionFormControl = new FormControl(undefined); - - public ngOnChanges() { - this.optionFormControl.setValue(this.defaultValue); + public constructor() { + effect(() => { + this.optionFormControl.setValue(this.defaultValue()); + }); } public onValueChange() { - this.valueChange.emit({ value: this.optionFormControl.value }); + const value = this.optionFormControl.value; + + if (value !== null) { + this.valueChange.emit({ value }); + } } }