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

Modal: Nuance outside interactions #52994

Merged
merged 4 commits into from
Aug 14, 2023
Merged

Conversation

stokesman
Copy link
Contributor

What?

Changes interactions on the overlay:

  • To not dismiss until clicked, thereby allowing to cancel dismissal by dragging back over the modal before releasing.
  • To permit opening the context menu without dismissal

Why?

Some portion of the audience will appreciate these nuances and they don't otherwise negatively affect any UX.

How?

Uses pointer event handlers and:

  • at pointerdown if the overlay was pressed with the primary pointer then it’s tracked.
  • at pointerup determines if the modal should be dismissed based on whether the overlay was the release target and whether the pointer (and button for mice) was primary.

Testing Instructions

  1. Open a modal.
  2. Confirm ability to open the context menu with an alt click on the overlay without dismissing the modal.
  3. Confirm ability to press the overlay without dismissing the modal.
  4. Confirm ability to cancel dismissal by dragging back over the modal before releasing the press.

Testing Instructions for Keyboard

The changes in question aren’t keyboard applicable.

Screenshots or screencast

@stokesman stokesman added [Type] Enhancement A suggestion for improvement. [Package] Components /packages/components labels Jul 26, 2023
Comment on lines 190 to 199
onPointerUp: ( { target, isPrimary, button } ) => {
const isSameTarget = target === pressTarget;
pressTarget = null;
if ( isPrimary && button === 0 && isSameTarget ) onRequestClose();
},
Copy link
Member

Choose a reason for hiding this comment

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

I might be missing something obvious, but what stops us from simply doing this?

Suggested change
onPointerUp: ( { target, isPrimary, button } ) => {
const isSameTarget = target === pressTarget;
pressTarget = null;
if ( isPrimary && button === 0 && isSameTarget ) onRequestClose();
},
onClick: ( event ) => {
if ( event.target === event.currentTarget ) {
onRequestClose();
}
},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It wasn't immediately obvious to me. I tried that first and it works except for supporting the ability to drag back over the modal to cancel the click. When mousedown is on the overlay and the mouseup is on the modal that's still a click from the perspective of the overlay (and target is currentTarget).

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see, good catch. Could we add a code comment about that too? I'm sure others will wonder the same.

Unfortunately this doesn't seem to be accurately testable in Jest, so I'll take note of it as a potential test to add when we set up Playwright tests for components.

Copy link
Member

@mirka mirka left a comment

Choose a reason for hiding this comment

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

I think this is a pretty important improvement, let's move forward with it!

@stokesman stokesman marked this pull request as ready for review August 11, 2023 17:09
@stokesman
Copy link
Contributor Author

Thanks for reviewing Lena! I added a comment as suggested. I also removed the condition concerning isPrimary. I'd been supposing it might be a good to cover a case on multi input devices (think touch screen laptop with mouse) but I think that’s over doing it and I don’t have a device like that for testing anyway.

@stokesman stokesman merged commit ebae2d5 into trunk Aug 14, 2023
51 checks passed
@stokesman stokesman deleted the update/modal-click-outside branch August 14, 2023 17:37
@github-actions github-actions bot added this to the Gutenberg 16.5 milestone Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants