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

[NavigationMenu] Menu closes when mouseenter + instantaneous click #2326

Closed
thgh opened this issue Aug 6, 2023 · 6 comments
Closed

[NavigationMenu] Menu closes when mouseenter + instantaneous click #2326

thgh opened this issue Aug 6, 2023 · 6 comments

Comments

@thgh
Copy link

thgh commented Aug 6, 2023

Bug report

Current Behavior

  1. Click Learn
  2. Learn menu opens
  3. Click Overview
  4. Overview menu is shortly visible and then closes

Expected behavior

  1. Click Learn
  2. Learn menu opens
  3. Click Overview
  4. Overview menu opens

Reproducible example

https://www.radix-ui.com/docs/primitives/components/navigation-menu

Suggested solution

The initial delay that "ignores" the first toggle, should be re-applied when a new menu item is opened.

Additional context

Your environment

Software Name(s) Version
Radix Package(s)
React n/a
Browser Chrome
Assistive tech
Node n/a
npm/yarn
Operating System
@josephkruse
Copy link

Duplicate of this issue:
#1630

There's a hacky fix in that thread.

@thgh
Copy link
Author

thgh commented Aug 29, 2023

Oh thanks for the context, it's the same underlying issue indeed. I don't want to disable hover, both should trigger the menu.

@josephkruse
Copy link

It doesn't disable hover just disables clicks for 1 seconds after hover.

https://codesandbox.io/p/sandbox/peaceful-nobel-gmlbyy?file=%2FApp.tsx

@thgh
Copy link
Author

thgh commented Aug 30, 2023

Thanks, I refactored it to this workaround for now:

function Item () {
  const fix = useTriggerFix()
  
  ...
        <NavigationMenu.Trigger {...fix}>
  ...
}

function useTriggerFix() {
  return useMemo(() => {
    let disable
    return {
      onClick: (e) => disable && e.preventDefault(),
      onPointerEnter: () => {
        clearTimeout(disable)
        disable = setTimeout(() => (disable = false), 1000)
      },
    }
  }, [])
}

@kachkaev
Copy link

Yeah seems like it’s a duplicate of #1630. A workaround can be found here: #1630 (comment).

@benoitgrelard
Copy link
Collaborator

Duplicate of #1630

@benoitgrelard benoitgrelard marked this as a duplicate of #1630 Mar 8, 2024
@benoitgrelard benoitgrelard added the Resolution: Duplicate This issue is a duplicate label Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants