laravel / nova-issues

556 stars 34 forks source link

Weird behavior when clicking on rows on the index page #5693

Closed Hannoma closed 1 year ago

Hannoma commented 1 year ago

Description:

"Open in a new tab" on the index page by holding the CTRL button down while clicking on a row does not work. Although one holds the CTRL button, and the resource detail page should open in a new tab, it redirects you to the detail page in the current tab. When locking the computer and unlocking it again, it now works. After reloading the page, the previous behavior occurs again.

crynobone commented 1 year ago

Unable to reproduce the issue, please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

pavol-revive commented 1 year ago

I suspect this is a problem with how the commandPressed is being handled in app/vendor/laravel/nova/resources/js/components/GlobalSearch.vue (probably introduced in https://nova.laravel.com/releases/4.21.0)

The goToSelectedResource() doesn't check the state of "command key being pressed" at the moment of the click, it checks it against stored this.commandPressed value.

The problem with this approach is when the "keyUp" event happens in a separate tab. In that case this.commandPressed value stays true even though no command key is pressed (anymore).

Steps to reproduce

If you now press and release the command key, the state is "reset" and correct behavior returns (until next "release in a different tab" event happens of course)

Btw. the same thing happens when you use "ctrl+tab" / "cmd+tab" to navigate the tabs in the browser (and you don't return to Nova right away), since the "command key release event" happens outside of Nova.

Possible fix

Use Vue's modifier keys for the correct behavior in GlobalSearch results

<button
    :dusk="item.resourceName + ' ' + item.index"
    @click.exact="novaVisitSelectedResource(item)"
    @click.ctrl="openSelectedResourceInNewTab(item)"
    @click.meta="openSelectedResourceInNewTab(item)"
    ...
>