netbox icon indicating copy to clipboard operation
netbox copied to clipboard

Global search keyboard shortcut

Open llamafilm opened this issue 1 year ago • 1 comments

NetBox version

v4.0.8

Feature type

New functionality

Triage priority

This is a very minor change

Proposed functionality

Pressing the slash / key from any webpage should move the cursor to the global search box, unless another text field already has focus. This is a common convention across many web services including Gmail and GitHub.

Use case

Nine times out of 10, the first thing I do when opening Netbox is click on global search. I've arrived the page using the keyboard (typing the URL), so it's un-ergonomic to move to the mouse for one click and then move back to the keyboard to type.

Database changes

No response

External dependencies

No response

llamafilm avatar Oct 21 '24 23:10 llamafilm

This was also brought up in https://github.com/netbox-community/netbox/issues/12749#issuecomment-1709667400

ITJamie avatar Oct 23 '24 21:10 ITJamie

One note on implementation: This will need to be done in a proper TypeScript model (as opposed to JS embedded in the HTML source).

jeremystretch avatar Feb 06 '25 18:02 jeremystretch

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

github-actions[bot] avatar May 08 '25 04:05 github-actions[bot]

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

github-actions[bot] avatar Jun 07 '25 04:06 github-actions[bot]

Since this FR wasn't accepted, I've patched base.html with this code on my server and it's a huge timesaver. If there is interest, I could try making this into a proper typescript module.

<script type="text/javascript">
// If the '/' key is pressed, focus the global search input
document.addEventListener('keydown', (event) => {
  if (event.target.matches('input, textarea, select') || document.body.classList.contains('modal-open')) {
    return;
  }
  if (event.key === '/') {
    const searchInput = document.querySelector('header input[name="q"]');
    console.log('Focusing search input');
    searchInput.focus();
    event.preventDefault();
  }
});
</script>

llamafilm avatar Jun 08 '25 21:06 llamafilm