-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[core] refactor(Popover): improve popover captureDismiss mechanism #4328
[core] refactor(Popover): improve popover captureDismiss mechanism #4328
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall looks like a reasonable approach
@adidahiya Thanks for the review, I run tests locally and completely forgot about react 15. Is there an script for running tests with that configuration? |
// an OVERRIDE inside a DISMISS does not dismiss, and a DISMISS inside an OVERRIDE will dismiss. | ||
const dismissElement = eventTarget.closest(`.${Classes.POPOVER_DISMISS}, .${Classes.POPOVER_DISMISS_OVERRIDE}`); | ||
const shouldDismiss = dismissElement != null && dismissElement.classList.contains(Classes.POPOVER_DISMISS); | ||
const isDisabled = eventTarget.closest(`:disabled, .${Classes.DISABLED}`) != null; | ||
if (shouldDismiss && !isDisabled && !e.isDefaultPrevented()) { | ||
if (shouldDismiss && !isDisabled && (!isEventPopoverCapturing || isEventFromSelf)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is isDisabled
still relevant here? Not sure if the check was to avoid preventDefault
on an event that should not have been touched, or if we genuinely didn't want to close the popover if its target is disabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure it's redundant, since a disabled element can't emit a click event. However I don't know if any blueprint component only uses disabled class but doesn't respect that rule (I checked anchor button and they do respect not triggering onClick) if there's no element which applies disabled class and allow clicking I can remove that too.
@ejose19 yes, it is possible to run those tests by setting an environment variable in your shell: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @ejose19
Fixes #2820
Checklist
Changes proposed in this pull request:
captureDismiss
preventDefault
/defaultPrevented
and instead use a more self contained approach to determine whether the popover should close in the presence ofcaptureDismiss