[@mantine/core] HoverCard: Fix dropdown closing when clicked #8097
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
HoverCard Dropdown Issue and Proposed Fix
Issue Description
The HoverCard dropdown closes unexpectedly when clicked, disrupting the user experience as it should remain open during interaction.
Root Cause
The issue occurs because
floating-ui
'suseDismiss
hook incorrectly triggers an outside click event, callingonChange(false)
to close the dropdown. TheuseHoverCard
hook's inneruseFloating
is only intended forwithinGroup
contexts, souseDismiss
should only be active whenwithinGroup
is enabled. However,useDismiss
is triggered regardless of this state. Additionally,useDismiss
checks if the dropdown is open before registering events internally, but the conditionenabled: typeof settings.opened === 'undefined'
maybe incorrect, leading to improper event registration.Proposed Fix
A small update is needed to ensure
useDismiss
is only active whenwithinGroup
is enabled, preventing the dropdown from closing unexpectedly outside this context, and works like before. Additionally, theenabled
check inuseDismiss
should be corrected to properly handle click-outside events, ensuring events are only registered when the dropdown is open and within thewithinGroup
context.