I'm using a Radix Popover that internally uses DismissableLayer. Inside of that Popover I have buttons that call event.stopPropagation() in their onPointerDown handler. After clicking on such a button and trying to exit the Popover relying on onPointerDownOutside, it requires 2 clicks instead of 1.
Expected behavior
I'd expect the Popover to close using a single click outside regardless if my content inside is stopping propagation.
The issue seems to come from the fact that after the 1st click the isPointerInsideReactTreeRef ref is being set to true in the onPointerDownCapture handler. During the same event, we should expect the handlePointerDown function to be called and set the ref to false. This ultimately does not happen because the event does not bubble up to the pointerdown listener.
I don't really have an idea how this could be fixed.
Bug report
Current Behavior
I'm using a Radix Popover that internally uses
DismissableLayer
. Inside of that Popover I have buttons that callevent.stopPropagation()
in theironPointerDown
handler. After clicking on such a button and trying to exit the Popover relying ononPointerDownOutside
, it requires 2 clicks instead of 1.Expected behavior
I'd expect the Popover to close using a single click outside regardless if my content inside is stopping propagation.
Reproducible example
CodeSandbox
Suggested solution
The issue seems to come from the fact that after the 1st click the
isPointerInsideReactTreeRef
ref is being set to true in theonPointerDownCapture
handler. During the same event, we should expect thehandlePointerDown
function to be called and set the ref to false. This ultimately does not happen because the event does not bubble up to thepointerdown
listener.I don't really have an idea how this could be fixed.
Additional context
For context, I discovered this when trying to combine Radix Popover with React-Aria Calendar inside. Related: https://github.com/adobe/react-spectrum/issues/5799#issuecomment-1936132882
Your environment