Skip to content
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

Custom modal aux click #6891

Merged
merged 6 commits into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions tensorboard/webapp/widgets/custom_modal/custom_modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,23 @@ export class CustomModal {
const customModalRef = new CustomModalRef(overlayRef);
this.customModalRefs.push(customModalRef);

// setTimeout to prevent closing immediately after modal open.
setTimeout(() => {
const outsidePointerEventsSubscription = overlayRef
.outsidePointerEvents()
.subscribe((event) => {
// Only close when click is outside of every modal
if (
this.customModalRefs.every(
(ref) =>
!isMouseEventInElement(event, ref.overlayRef.overlayElement)
)
) {
this.closeAll();
}
});
customModalRef.subscriptions.push(outsidePointerEventsSubscription);
});
const outsidePointerEventsSubscription = overlayRef
.outsidePointerEvents()
.subscribe((event) => {
Copy link
Member

Choose a reason for hiding this comment

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

As I understand, the previous version of the code was executing immediately in some browsers (but apparently not in all of them), causing the event handler to be attached right before the "mouse up" event, or something like this, causing it to close it.

Can we instead check the type of event? Or something like this, to only match clicks? If an alternative solution is more complex, or difficult to validate, or if what I'm saying is not accurate or something, I'm ok with this solution. Just thought I'd ask.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh this is better! I hadn't realized that there are two separate events for "right clicking": contextmenu (immediately triggers the system context menu) and auxclick (triggers when mousedown and mouseup occurs in the same element)

Since we're using contextmenu to open the modal, I updated the code to simply ignore the auxclick events, which should have the effect of ignoring the right click mouseup. To close the modal, left clicks and contextmenu events can still be used.

// Prevent the right click mouseup event from immediately closing the modal.
if (event.type === 'auxclick') return;

// Only close when click is outside of every modal
if (
this.customModalRefs.every(
(ref) =>
!isMouseEventInElement(event, ref.overlayRef.overlayElement)
)
) {
this.closeAll();
}
});
customModalRef.subscriptions.push(outsidePointerEventsSubscription);

const keydownEventsSubscription = overlayRef
.keydownEvents()
Expand Down
Loading