Skip to content

docs(topbar): tap-to-open Examples/Documentation dropdowns on touch#1993

Closed
zherendong wants to merge 1 commit into
cocoindex-io:mainfrom
zherendong:zheren/topbar-touch-dropdown
Closed

docs(topbar): tap-to-open Examples/Documentation dropdowns on touch#1993
zherendong wants to merge 1 commit into
cocoindex-io:mainfrom
zherendong:zheren/topbar-touch-dropdown

Conversation

@zherendong
Copy link
Copy Markdown
Contributor

@zherendong zherendong commented May 19, 2026

Pain point

When I was on my phone tapping around the docs / examples site, the Examples and Documentation items in the topbar each have a dropdown (v1 / v0). On desktop it shows up on hover, which is great — but on touch the hover never fires, so my first tap just navigated me straight to v1. I never even got the chance to pick v0.
ScreenShot_2026-05-18_151217_646

Fix

Made the first tap on those dropdown triggers open the menu instead of navigating, but only on touch / no-hover devices (matchMedia('(hover: none)')). The second tap (or tapping a menu item) navigates as normal. Outside-tap and Escape close it. Desktop hover is untouched.

Two tiny changes:

  • globals.css — added .nav-dd.open to the existing :hover / :focus-within rules so a JS-toggled class can reveal the menu.
  • Topbar.astro — small script inside the existing <script> block that wires up the tap intercept on (hover: none) devices.

How I verified

Ran the dev server locally and drove it with Playwright in two contexts:

  • Touch context (hasTouch: true, viewport 1280×800 so desktop nav is rendered): first tap opens the dropdown without navigating, .open class is applied, menu becomes visible; outside tap closes; tapping the v0 entry navigates correctly. Same flow checked for the Documentation dropdown. 9/9 assertions pass.
  • Desktop context (mouse, no touch): hover still reveals the menu without clicking, and clicking the trigger still navigates straight to /docs/examples — no regression.

On touch / no-hover devices the desktop hover never fires, so the first
tap on the Examples / Documentation trigger anchor used to navigate
straight to v1 before the user could pick v1 vs v0. Intercept that
first tap to open the menu; second tap (or selecting an item)
navigates. Desktop hover behavior is unchanged.
@zherendong zherendong closed this May 19, 2026
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.

1 participant