hotwired / turbo

The speed of a single-page web application without having to write any JavaScript
https://turbo.hotwired.dev
MIT License
6.54k stars 415 forks source link

Don't lose focus due to autofocus when morphing pages #1267

Closed jorgemanrubia closed 1 month ago

jorgemanrubia commented 1 month ago

Before this change, Turbo would always focus on the first element with [autofocus] when a page refresh with morphing happened (default behavior inherited from PageRenderer). With this change, it will never autofocus when a page refresh with morphing happens.

This is meant to solve the problem where you are writing on a form, and it loses the focus because a broadcasted page refresh arrives.

jorgemanrubia commented 1 month ago

I'll look into those tests...

jorgemanrubia commented 1 month ago

Thanks for helping with those tests @afcapel 🙏