Skip to content

Conversation

@mcous
Copy link
Contributor

@mcous mcous commented Jan 13, 2025

Overview

In browsers, if a click mousedown starts in one element and mouseup ends in another element, the click event is fired on the lowest common ancestor of the two elements.

If the button is pressed on one element and the pointer is moved outside the element before the button is released, the event is fired on the most specific ancestor element that contained both elements

MDN - click event

In most cases, this ancestor is going to trigger our clickOutside logic, resulting in frustrating user experiences, especially when selecting text.

Change log

Swap click listener for mousedown and mouseup listeners using the same "is target outside?" logic. If and only if both events are outside the target element, the handler is fired

Copy link
Contributor Author

@mcous mcous left a comment

Choose a reason for hiding this comment

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

Missing test

Copy link
Member

@mrloureed mrloureed left a comment

Choose a reason for hiding this comment

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

LGTM!

@mcous mcous merged commit 2c8cd1d into main Jan 14, 2025
4 checks passed
@mcous mcous deleted the APP-6535/mcous/click-outside-fix branch January 14, 2025 17:43
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

Successfully merging this pull request may close these issues.

4 participants