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

Menu trigger items events are blocked #2157

Open
ambethia opened this issue Jan 5, 2025 · 0 comments
Open

Menu trigger items events are blocked #2157

ambethia opened this issue Jan 5, 2025 · 0 comments

Comments

@ambethia
Copy link

ambethia commented Jan 5, 2025

🐛 Bug report

I am unable to style the :active state of a menu trigger item (e.g. a button).

💥 Steps to reproduce

  1. Have a trigger with styles for :active the pseudo-class.
  2. Press the trigger.

💻 Link to reproduction

CodeSandbox reproduction: https://codesandbox.io/p/sandbox/mc532c

🧐 Expected behavior

I expect to see the :active pseudo-class applied to my trigger while pressed.

🧭 Possible Solution

I narrowed this down to the event.preventDefault() in onPointerDown(event) on getTriggerProps(). If I remove the preventDefault() it does work as expected, the event bubbles up to the native element so we can style it.

If stopping the propagation of this event is necessary, can we add some data-* attribute to the trigger props that can be hooked so this state can be styled? Right now it doesn't appear anything in the DOM changes for the element until the mouse is released.

🌍 System information

Software Version(s)
Zag Version 0.80.0
Browser Firefox
Operating System macOS

📝 Additional information

I have a button that animates slightly on hover and depresses when clicked. Currently, the animation stays locked in the :hover state until the menu is opened (on mouse up). I can style it's open state to appear depressed once the mouse is released, but this feels jarring and it doesn't behave like the other "native" buttons.

Here's the current behavior; the circle around cursor indicated the mouse is pressed:

no-active.mov

Here's what it looks like if I comment out the event.preventDefault():

active.mov
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

No branches or pull requests

1 participant