Skip to content

Conversation

@kalicki2k
Copy link

@kalicki2k kalicki2k commented Mar 14, 2025

  • 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.

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

- 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.
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 14, 2025

npm i https://pkg.pr.new/@nuxt/ui@3571

commit: 368f840

@benjamincanac benjamincanac requested a review from romhml March 15, 2025 11:12
const element = document.getElementById(event.errors[0].id)
element?.focus()
element?.scrollIntoView({ behavior: 'smooth', block: 'center' })
setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit hacky, can we use nextTick instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit hacky, can we use nextTick instead?

indeed, as the main thread could be put on hold by the browser/OS while setTimeout run just fine in another thread taking us nowhere 😕

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried nextTrick, but it does not work. That's why I used setTimeout. @romhml

@benjamincanac benjamincanac marked this pull request as draft April 22, 2025 20:06
@kalicki2k kalicki2k closed this Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v3 #1289

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants