From 77f63b6ac34bb2c9a095d2ed3ed165730943ce96 Mon Sep 17 00:00:00 2001 From: Sebastian Kalicki Date: Fri, 14 Mar 2025 16:05:35 +0100 Subject: [PATCH] fix: add setTimeout to ensure element receives focus - Wrap focus and scrollIntoView calls in a setTimeout with 0ms delay. - This allows the browser to complete its render cycle before applying focus. - Fixes issue where the input field was found but not focused. --- .../components/content/examples/form/FormExampleOnError.vue | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/app/components/content/examples/form/FormExampleOnError.vue b/docs/app/components/content/examples/form/FormExampleOnError.vue index 801e7b87c4..b7377d7d01 100644 --- a/docs/app/components/content/examples/form/FormExampleOnError.vue +++ b/docs/app/components/content/examples/form/FormExampleOnError.vue @@ -22,8 +22,10 @@ async function onSubmit(event: FormSubmitEvent) { async function onError(event: FormErrorEvent) { if (event?.errors?.[0]?.id) { const element = document.getElementById(event.errors[0].id) - element?.focus() - element?.scrollIntoView({ behavior: 'smooth', block: 'center' }) + setTimeout(() => { + element?.focus() + element?.scrollIntoView({ behavior: 'smooth', block: 'center' }) + }, 0) } }