laravel / nova-issues

556 stars 34 forks source link

Searchable fields in Action modals do not focus correctly #6335

Closed puzzledmonkey closed 7 months ago

puzzledmonkey commented 7 months ago

Description:

When opening a searchable input in an Action modal, the input does not focus correctly.

Detailed steps to reproduce the issue on a fresh Nova installation:

Similar to https://github.com/laravel/nova-issues/issues/6276

crynobone commented 7 months ago

Yes, this is the expected behavior to solve bug reported in #6276

puzzledmonkey commented 7 months ago

So now users will need to click twice in order to start typing? That seems like a regression to me, the functionality isn't as smooth as it used to be here.

Is there no other solution?

crynobone commented 7 months ago

I would argue the current behavior make SearchInput behave similar to <select />, you can toggle options on SearchInput and <select /> by pressing the spacebar key.

puzzledmonkey commented 7 months ago

Sorry @crynobone I don't really believe that.

If that's the case, why does the 2nd, 3rd time etc, that you click the dropdown, it focuses as expected with one click.

It's only the first time you open the search input dropdown that it doesn't focus correctly.

It looks like a bug to me..?

puzzledmonkey commented 7 months ago

Also, line 198 of SearchInput clearly tries to focus the search input field (which works on the 2nd, 3rd, etc. time you open it).

Please can you re-open this issue @crynobone as it's definitely a bug.

puzzledmonkey commented 7 months ago

@crynobone @davidhemphill i managed to fix this like so - just wrap line 198 in a timeout so the focus trap initiates first, and THEN the search field is focused. this works the first time as well as any subsequent times.

setTimeout(() => {
  this.$refs.search.focus()
}, 0)