hotwired / turbo

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

Proposal: autofocus attribute on turbo frames #952

Closed mkdynamic closed 4 months ago

mkdynamic commented 1 year ago

I am using a custom renderer with Turbo Frames (specifically morphdom) which manages maintaining focus. However, if any element in the new set have an autofocus attribute they will steal focus after the render due to the behavior of FrameRenderer:

https://github.com/hotwired/turbo/blob/da647a63950c6f834fb0fbcf9315bee2be408cbe/src/core/frames/frame_renderer.ts#L42-L52

Proposal is to add an autofocus attribute to the turbo-frame element (with a default of true) – similar to way you can control the auto scrolling behavior:

https://turbo.hotwired.dev/reference/frames#html-attributes

brunoprietog commented 4 months ago

Hi @mkdynamic, this is not possible. You can do scroll to a Turbo frame, but a Turbo frame is not focusable, so it doesn't make much sense to do this. Closing for now