From 30b33cf2967081c4c192bd03ba667ca5f1cbf1d7 Mon Sep 17 00:00:00 2001 From: abdullah2993 Date: Wed, 4 Oct 2023 19:06:39 +0500 Subject: [PATCH] Checkbox: Add blur and focus event --- src/app/components/checkbox/checkbox.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/app/components/checkbox/checkbox.ts b/src/app/components/checkbox/checkbox.ts index d36ad5fbf5d..a25e9472f49 100755 --- a/src/app/components/checkbox/checkbox.ts +++ b/src/app/components/checkbox/checkbox.ts @@ -29,8 +29,8 @@ export const CHECKBOX_VALUE_ACCESSOR: any = { [readonly]="readonly" [value]="value" [checked]="checked()" - (focus)="onFocus()" - (blur)="onBlur()" + (focus)="onInputFocus($event)" + (blur)="onInputBlur($event)" (change)="handleChange($event)" [disabled]="disabled" [attr.tabindex]="tabindex" @@ -166,6 +166,18 @@ export class Checkbox implements ControlValueAccessor { * @group Emits */ @Output() onChange: EventEmitter = new EventEmitter(); + /** + * Callback to invoke when the receives focus. + * @param {Event} event - Browser event. + * @group Emits + */ + @Output() onFocus: EventEmitter = new EventEmitter(); + /** + * Callback to invoke when the loses focus. + * @param {Event} event - Browser event. + * @group Emits + */ + @Output() onBlur: EventEmitter = new EventEmitter(); @ViewChild('cb') inputViewChild: Nullable; @@ -235,13 +247,15 @@ export class Checkbox implements ControlValueAccessor { } } - onFocus() { + onInputFocus(event: Event) { this.focused = true; + this.onFocus.emit(); } - onBlur() { + onInputBlur(event: Event) { this.focused = false; this.onModelTouched(); + this.onBlur.emit(); } focus() {