Skip to content

Conversation

@sarahboyce
Copy link
Contributor

Fixes #2349

I also added playwright to have a way to test JavaScript (might be controversial and can remove if wanted)

@sarahboyce sarahboyce force-pushed the fix-search-hot-key-desktop branch 2 times, most recently from 549b303 to 9d9dbf6 Compare November 24, 2025 13:46
@sarahboyce sarahboyce requested a review from a team November 24, 2025 14:20
Copy link
Member

@adamzap adamzap left a comment

Choose a reason for hiding this comment

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

I'm still catching up on recent PRs...it looks like we have two elements with the same ID on the page now. I wonder if there's a way to achieve the same behavior with a single element and responsive styling. Do you or others think this is worth pursuing?

// Update search input placeholder text based on the user's operating system
(function () {
const el = document.getElementById('id_q');
const el = querySelectorVisible('#id_q');
Copy link
Member

@adamzap adamzap Nov 24, 2025

Choose a reason for hiding this comment

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

Would you be opposed to updating the placeholder on both elements?

It would simplify the code here and allow us to factor the querySelectorVisible function that you created out into the other handler. Before this commit, this file didn't add anything to the global namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like its usually a good idea to use a class or some other selector and not id, if we expect multiple elements to have that id. Or maybe have id like id_q_mobile and id_q for mobile and desktop respectively. Multiple elements having same id is usually considered invalid HTML. I do like the querySelectorVisible function though, and I don't have a super strong opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a bit fiddly to pull off but I think I've managed it. I pushed up a second commit in case the previous version is preferred but now have unique html ids 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

It is a bit fiddly. Not to be a pain but I wonder if should have just used a class instead of an id in the first commit and just gone with that. Do you think that would be cleaner and maybe makes more sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I remove the id, I think I need to remove the label as this is linked to the field using the field id 🤔
Is that acceptable?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah you are right. That's not acceptable as well. In that case, I think the fiddly bit maybe makes sense and is worth the effort. Thanks!

@sarahboyce
Copy link
Contributor Author

I wonder if there's a way to achieve the same behavior with a single element and responsive styling. Do you or others think this is worth pursuing?

I originally tried doing this but found it challenging. The search bar duplication aligns with the light/dark mode toggle duplication and show/hide behavior, aligning to that was easier to acheive given the existing html structure

@sarahboyce sarahboyce force-pushed the fix-search-hot-key-desktop branch from 9d9dbf6 to f15d207 Compare November 24, 2025 17:29
@sarahboyce sarahboyce force-pushed the fix-search-hot-key-desktop branch from f15d207 to c37f9f9 Compare November 24, 2025 17:34
@sarahboyce sarahboyce force-pushed the fix-search-hot-key-desktop branch from 7e511ca to b458667 Compare November 25, 2025 14:48
];

const el = inputs.find(isVisible);
if (!el) return;
Copy link
Member

Choose a reason for hiding this comment

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

checkVisibility is baseline 2024, so maybe we can replace the isVisible definition and call with:

  const el = inputs.find((el) => el.checkVisibility());

Or is that too modern? This section of the README seems outdated. I'll follow up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should use it for both updating the placeholder and adding the hotkey, then if it's not supported, it won't be advertised in the placeholder

Copy link
Contributor

Choose a reason for hiding this comment

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

I think either way is fine. @sarahboyce are you thinking of using checkVisibility? Apart from that, I think this PR is ready to be merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have pushed up a commit with this change 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hotkey for focus-on-search broken

3 participants