Focus on Action Modal open?

Hi, is it possible to focus a form field after a action modal is opened?

I use AlpineJS dispatch an Event which opens the Modal and I'm able to pass in the name of the field which is needed to be focused.

But I'm not sure if it's possible currently, I know I can execute PHP code when the modal is opened. However I probably need to execute some JS.

I also tried using ->autofocus() on the form fields with a Closure that checks which field to focus, like:

->autofocus(fn() => $this->autofocus === 'field-name')


But autofocus seems not to do anything in modals.
Was this page helpful?