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

fix(web): clicking away closes context menu #16989

Merged
merged 3 commits into from
Mar 21, 2025
Merged

Conversation

ben-basten
Copy link
Member

@ben-basten ben-basten commented Mar 19, 2025

Description

Fixes #16147

Using "click" event handler to detect whether there's been a click outside of the context menu, rather than the "mousedown" event in the use:clickOutside Svelte action.

The cause?

This bug was likely introduced in #15900, where the clickOutside listener changed was changed from "click" to "mousedown".

The asset viewer page uses the @zoom-image/svelte library to handle zooming, which listens for "pointerdown" events and uses event.preventDefault to override default behavior. According to the MDN docs for PointerEvent, this stops the mouse events from firing and therefore breaks the clicking outside behavior in Immich.

How Has This Been Tested?

  1. Navigate to the asset viewer
  2. Open the context menu with the ellipses "..." button in the top right to open the context menu
  3. Click away to test that the context menu closes

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if applicable
  • I have no unrelated changes in the PR.
  • I have confirmed that any new dependencies are strictly necessary.
  • I have written tests for new code (if applicable)
  • I have followed naming conventions/patterns in the surrounding code

@mertalev
Copy link
Contributor

mertalev commented Mar 19, 2025

Is there a way to fix this and still avoid making a mouse up outside the modal dismiss the modal, as #15900 does?

@ben-basten
Copy link
Member Author

ben-basten commented Mar 19, 2025

Is there a way to fix this and still avoid making a mouse up outside the modal dismiss the modal, as #15900 does?

Looks like there is, thanks for the poke to make a better fix. Using the pointerdown event directly works.

I'll do some more testing on mobile vs desktop to make sure it's looking ok.

@ben-basten ben-basten force-pushed the fix/close-context-menu branch from b35a2cd to 0d2cf47 Compare March 21, 2025 01:39
@ben-basten
Copy link
Member Author

Is there a way to fix this and still avoid making a mouse up outside the modal dismiss the modal, as #15900 does?

Hey @mertalev, this PR maintains the mouseup fix from #15900. Rather than changing the use:clickOutside logic that determines whether UI elements like the modal should be closed, I implemented a custom click handler that only the context menu uses. The modal is unaffected by this change.

Using the pointerdown event directly works.

I'll do some more testing on mobile vs desktop to make sure it's looking ok.

I've decided to revert the simpler fix of using the pointerdown event (0d2cf47) after doing some testing with an iPad. I found that specifically for touch devices, this caused an issue where tapping outside of a modal to close it could click elements underneath the modal before it's dismissed.

@ben-basten ben-basten marked this pull request as ready for review March 21, 2025 02:05
Copy link
Contributor

Deploying preview environment to https://pr-16989.preview.internal.immich.cloud/

@alextran1502 alextran1502 merged commit 3c87341 into main Mar 21, 2025
49 checks passed
@alextran1502 alextran1502 deleted the fix/close-context-menu branch March 21, 2025 13:39
@github-actions github-actions bot removed the preview label Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Context menu cannot be closed with click outside
3 participants