-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Bug]: Dialog/Modal does not close by mouse click when wrapped in component with outer onClick event #414
Comments
@bennettdams , I think the button event is bubbling to the Card and since Card has a click handler so it is getting invoked. The following structure is responsible for the same I guess.
Now the button click reaches Card and the onClick gets triggered. May be putting some sort of safeguards on useModal could help.
|
@bishwenduk029 Thanks! Yes, using safeguards does help and fixes the issue. I'm not that deep into event propagation - shouldn't the bubbling be stoped by the handlers ( |
Hey! Thank you for your bug report! This should be fixed in #422, and will be available in the next release. I also updated your reproduction CodeSandbox that includes the fix: https://codesandbox.io/s/heuristic-cdn-k9oiq |
* re-export the `screen` utility for quick debugging purposes * stop event propagation when clicking inside a Dialog Fixes: #414
@RobinMalfait What a quick response... Thanks a lot! |
* Fixed typos (#350) * chore: Fix typo in render.ts (#347) * Better vue link (#353) * Better vue link * add better React link Co-authored-by: Robin Malfait <[email protected]> * Enable NoScroll feature for the initial useFocusTrap hook (#356) * enable NoScroll feature for the initial useFocusTrap hook Once you are using Tab and Shift+Tab it does the scrolling. Fixes: #345 * update changelog * Revert "Enable NoScroll feature for the initial useFocusTrap hook (#356)" This reverts commit 19590b0. Solution is not 100% correct, so will revert for now! * Improve search (#385) * make search case insensitive for the listbox * make search case insensitive for the menu * update changelog * add `disabled` prop to RadioGroup and RadioGroup Option (#401) * add `disabled` prop to RadioGroup and RadioGroup Option Also did some general cleanup which in turn fixed an issue where the RadioGroup is unreachable when a value is used that doesn't exist in the list of options. Fixes: #378 * update changelog * Fix type of `RadioGroupOption` (#400) Match RadioGroupOption value types to match modelValue allowed types for RadioGroup * update changelog * fix typo's * chore(CI): update main workflow (#395) * chore(CI): update main workflow * Update main.yml * fix dialog event propagation (#422) * re-export the `screen` utility for quick debugging purposes * stop event propagation when clicking inside a Dialog Fixes: #414 * improve dialog escape (#430) * Make sure that `Escape` only closes the top most Dialog * update changelog * add defaultOpen prop to Disclosure component (#447) * add defaultOpen prop to Disclosure component * update changelog Co-authored-by: Shuvro Roy <[email protected]> Co-authored-by: Alex Nault <[email protected]> Co-authored-by: Eugene Kopich <[email protected]> Co-authored-by: Nathan Shoemark <[email protected]> Co-authored-by: Michaël De Boey <[email protected]>
What package within Headless UI are you using?
@headlessui/react
What version of that package are you using?
v1.0.0
What browser are you using?
Chrome
Reproduction repository
https://codesandbox.io/s/proud-voice-dvdru?file=/src/App.tsx
Describe your issue
When the "Dialog" component is used in a component that is used in a component where an
onClick
handler is defined, the Dialog's is not closing when clicking on its button/on the overlay. Pressing the escape key works though.Setup:
ChildWithModal
component, that brings its own "Dialog"Card
component, clickable if neededHere's an example with two childs. Only difference: in one example clicking the
Card
component should also open the Dialog.App.tsx
Card.tsx
I'm not sure why preventing default/stopping propagation does not help here.
Demonstration
Full reference, but I would suggest looking at the CodeSandbox:
Click to expand
The text was updated successfully, but these errors were encountered: