Autofocus not working

I have used the ->autofocus() in the main field of the form, but when I click on CREATE button, the form appears but the field is not focused at all. Is is happening to me in all resources. Any idea, please?
No description
19 Replies
Dennis Koch
Dennis Koch2y ago
I think someone else had this issue. Not sure if it's related to Filament or Livewire. Best to open an issue on GitHub.
LeandroFerreira
php artisan about what is the Filament version?
Albert Lens
Albert LensOP2y ago
It is version 3.0.0
No description
LeandroFerreira
run composer update it is working here
Albert Lens
Albert LensOP2y ago
done!!! But still NOT working. In any Resource. 😩
LeandroFerreira
console errors? Can you create a repo on github?
Albert Lens
Albert LensOP17mo ago
I have a repo: https://github.com/albertlens/rds_notarios/tree/seguimiento Any help will be highly appreciated. Thank you.
GitHub
GitHub - albertlens/rds_notarios at seguimiento
Contribute to albertlens/rds_notarios development by creating an account on GitHub.
Mikazor
Mikazor17mo ago
@albertlens did you find a solution? I Have the same problem
awcodes
awcodes17mo ago
I think this is a problem when multiple livewire requests are made. Seems to me that autofocus works fine with one request, but additional requests, like for things with entangled state like selects or fileuploads cause additional requests.
Mikazor
Mikazor17mo ago
I have a pretty simple form:
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->autofocus()
->maxLength(255)
->columnSpanFull()
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->autofocus()
->maxLength(255)
->columnSpanFull()
]);
}
awcodes
awcodes17mo ago
When you load the page how many livewire requests do you see in the network tab of dev tools? Autofocus has always seemed buggy to me in LW though.
Mikazor
Mikazor17mo ago
Only 1 http://localhost/livewire/update
awcodes
awcodes17mo ago
Interesting. I’ve had to go as far as implementing a js solution in some of my apps. Still haven’t found a good solid reason for it not working sometimes. Even trap seems to loose focus on modals sometimes.
Mikazor
Mikazor17mo ago
This is a request for a global search. If I deactivate it, there are no requests
awcodes
awcodes17mo ago
Yea. Not 100% sure. I’ve seen issues with it even in LW2 in non filament apps, so I’m sure it’s not a filament thing. Just haven’t been able to track down what’s causing it to lose focus after the page load.
Mikazor
Mikazor17mo ago
Ok. I'll try to recreate it in a clean project and report the bug It works in a fresh repository. So there is a problem in our code
Mikazor
Mikazor17mo ago
I reproduced the bug. https://github.com/filamentphp/filament/issues/8296 This happens because ->sidebarCollapsibleOnDesktop() in AdminPanelProvider
GitHub
Autofocus not working with ->sidebarCollapsibleOnDesktop() · Issue ...
Package filament/filament Package Version v3.0.39 Laravel Version v10.22.0 Livewire Version v3.0.1 PHP Version 8.1 Problem description ->autofocus() doesn't make any effect when ->sidebar...
Albert Lens
Albert LensOP17mo ago
I have observed a strange behaviour. Locally it is not working, but when I take the code to production, I mean, I publish it on GitHub and update my end-user website which I control with forge.laravel it does work. Locally it does not work. Up in the server it DOES work. No changes at all in code. Strange, isn't it? And, besides, up in the server, when accessing via mobile phone, it does NOT work, either.
gergo85
gergo8516mo ago
When I put autofocus in code, it worked on the first page refresh, but not after that.

Did you find this page helpful?