Autofocus in a Modal
Is there anyway to get the autofocus to work on input fields in slideovers/modals?
It currently doesn't focus the field when opening a modal or slideover but does work on the full page form.
5 Replies
Hmm odd, now it doesn't appear to be working in the full page forms. Odd. Are there certain things that could cause
->autofocus()
to not cause the form to be autofocused on loading?
Hmm for what it's worth, autofocus="autofocus"
does get added to the input fields. Odd that that it doesn't actually focus that field.. 🤔I think autofocus only works on page load. I have seen issues, even with LW2 though where autofocus doesn’t work.
Is there a way you know of to use javascript to focus a Filament Input field? Like somewhat built into the framework?
Not built in. I have used JS to autofocus the email field on the login page before.
And just added it with a renderHook.
Not very clean, but it works. This is also in v2. But same principle applies in v3.
Hmm that maybe could work. Just looking for the various forms across the page, whether edit page or modal, to have the first field autofocused when it opens. Will try to play around with the render hooks
Thanks
Well this works... lol - Focuses the first input field on the page as well as a modal when it pops up.
Need to do some rework to make it auto focus the first specified
autofocus=autofocus
input on the page.
Ohh! this works great!
This auto selects the first input element on the page (edit page OR modal (even the slideover)).