Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow middle-clicking the search button with progressive enhancement #2004

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

YoshiRulz
Copy link
Collaborator

@YoshiRulz YoshiRulz commented Oct 5, 2024

Implements #1878.
RetroEdit's earlier draft used JS to add an event handler specifically for MMB. I feel that's the wrong approach, and it should instead use the browser's built-in handling for <a/>.
This changeset uses JS to replace the <button/> with an <a/>, then adds an event handler for onclick (which is a misnomer and is not specific to LMB) which restores the <button/>-like submit behaviour.

// allow middle-clicking the search button to open in new tab
const searchBtnElem = document.querySelector(/*ul.navbar-nav */'form[action="/Search/Index"] button[type="submit"]');
// is there a function for this? reverse Element.querySelector?
let searchFormElem = searchBtnElem.parentElement;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if there is not a searchBtnElem on the page? this would be a javascript error. Also this runs on every page load. This needs to be fast, I'm not sure that query selector is. Adding an id would be okay I think.

I also don't like this approach, or possibly any approach, the complexity vs value I think is questionable

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the search bar not on every page? I could easily handle that case if not.

@YoshiRulz
Copy link
Collaborator Author

YoshiRulz commented Oct 30, 2024

I just remembered the search has a char limit, which isn't currently enforced client-side but could easily be added to this click handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants