Skip to content

[MISC][XY] Prevent Drawer from closing during text selection#915

Open
ninjasheeps wants to merge 6 commits intomasterfrom
fix-drawer-overlayclick
Open

[MISC][XY] Prevent Drawer from closing during text selection#915
ninjasheeps wants to merge 6 commits intomasterfrom
fix-drawer-overlayclick

Conversation

@ninjasheeps
Copy link
Contributor

Changes
Fixed issue where drawer would auto-close when users highlight text inside the drawer and drag their mouse outside of drawer

Changes:

  • Added handleDocumentMouseDown listener to track interaction origin

  • Updated handleWrapperClick to close drawer if both mousedown AND click happened outside of drawer

  • delete branch

@ninjasheeps ninjasheeps requested a review from qroll December 18, 2025 09:37
@qroll qroll added the type: bug Something isn't working label Dec 22, 2025
@ninjasheeps ninjasheeps force-pushed the fix-drawer-overlayclick branch from 0f048fc to 0f26edd Compare December 23, 2025 03:11
@ninjasheeps ninjasheeps requested a review from qroll December 23, 2025 03:21
@ninjasheeps ninjasheeps force-pushed the fix-drawer-overlayclick branch from 669c897 to 619ef5a Compare January 2, 2026 07:02
@ninjasheeps ninjasheeps requested a review from qroll January 2, 2026 08:53
Copy link
Contributor

@qroll qroll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

summing up our earlier discussion!

  1. Modal and ModalV2 to implement this
    const childRef = useRef<HTMLDivElement>(null);
    const childWithRef =
        children && React.cloneElement(children, { ref: childRef });

    <Overlay containerRef={childRef}>
      // other code here
       {childWithRef} // instead of children
    </Overlay>
  1. ModalV2.Card to forward the ref
  2. Overlay to also restore the childWithRef logic
  3. In Overlay's handleWrapperClick, the container will be containerRef?.current ?? childWithRef?.current

@ninjasheeps ninjasheeps force-pushed the fix-drawer-overlayclick branch from 03e3f7d to 04ed97b Compare January 29, 2026 08:41
@ninjasheeps ninjasheeps requested a review from qroll February 4, 2026 05:43
@ninjasheeps ninjasheeps force-pushed the fix-drawer-overlayclick branch from c32fef9 to f57bb60 Compare February 20, 2026 03:52
@ninjasheeps ninjasheeps requested a review from qroll February 23, 2026 05:49
@qroll
Copy link
Contributor

qroll commented Mar 10, 2026

was updating the docs and realised the behaviour was still inconsistent on certain examples (e.g. on the Overlay stories)

I've tried tweaking the logic here: 7f1706b

  • in some cases we can bypass the logic by checking if the wrapper was directly clicked on
  • clicking on the container should also count as an inside click - the original negation on clickedInsideModal also negated the clickOnContainer check

does this make sense to you?

@ninjasheeps
Copy link
Contributor Author

yep, this makes sense to me. thank you so much for working on this!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants