From 207830b02126ef9b7cb85fbb7401d4e770be08aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Thu, 15 Feb 2024 13:59:46 +0300 Subject: [PATCH] Fixed #14745 - Calendar | Autofocus not working --- src/app/components/autofocus/autofocus.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/app/components/autofocus/autofocus.ts b/src/app/components/autofocus/autofocus.ts index 6babd0d1998..1412948a142 100644 --- a/src/app/components/autofocus/autofocus.ts +++ b/src/app/components/autofocus/autofocus.ts @@ -24,16 +24,18 @@ export class AutoFocus { ngAfterContentChecked() { if (!this.focused) { if (this.autofocus) { - const focusableElements = DomHandler.getFocusableElements(this.host.nativeElement); + setTimeout(() => { + const focusableElements = DomHandler.getFocusableElements(this.host.nativeElement); - if (focusableElements.length === 0) { - this.host.nativeElement.focus(); - } - if (focusableElements.length > 0) { - focusableElements[0].focus(); - } + if (focusableElements.length === 0) { + this.host.nativeElement.focus(); + } + if (focusableElements.length > 0) { + focusableElements[0].focus(); + } - this.focused = true; + this.focused = true; + }); } } }