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(overlays): only close the top overlay on [Esc] #2198

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

gerjanvangeest
Copy link
Member

What I did

Copy link

changeset-bot bot commented Feb 26, 2024

🦋 Changeset detected

Latest commit: 9329d56

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@lion/ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

ctrl2.contentNode.dispatchEvent(new KeyboardEvent('keyup', { key: 'Escape' }));
await aTimeout(0);
expect(ctrl2.isShown).to.be.false;
expect(ctrl1.isShown).to.be.true;
Copy link
Member

Choose a reason for hiding this comment

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

Does this test fail when _blocksEscKeyHandler is left out of the equation?

I would expect the keyup event to never reach ctrl1.contentNode, as ctrl2.contentNode and ctrl1.contentNode are siblings.

The test should probably create a setup where ctrl2.contentNode is nested inside ctrl1.contentNode

this.__shownList = this.shownList.filter(ctrl => ctrl !== ctrlToHide);
setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Can we explain what this code does and why the timeout is needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

It removes the _blocksEscKeyHandler from the next overlay.
If there is no timeout, the unblocking will be done before the Esc will trigger the hide overlay. If you unblock it one tick later, it all works as expected.

* @param {KeyboardEvent} ev
* @private
*/
__escKeyHandler(ev) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can also check this.handleHidesOnOutsideEsc here (instead of overriding the __escKeyHandlerin _handleHidesOnOutsideEsc...)

(Know you didn't write it, but while we're at it :))

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but we don't want to have the _blocksEscKeyHandler in that function.
Then its better to have a separate escKeyOutisideHandler

@@ -629,6 +654,30 @@ describe('OverlayController', () => {
ctrl.contentNode.dispatchEvent(new KeyboardEvent('keyup', { key: 'Escape' }));
expect(ctrl.isShown).to.be.true;
});

it('hides all overlays when [escape] is pressed on outside element', async () => {
Copy link
Member

@tlouisse tlouisse Mar 8, 2024

Choose a reason for hiding this comment

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

I wonder if the whole approach still works if we have two ctrls: ctrl1 with hidesOnOutsideEsc and ctrl2 with hidesOnEsc. And ctrl2 is nested in ctrl1 (its contentNode is nested).

Would ctrl1 still be autonomous and be closed? (I suspect not, as _blocksEscKeyHandler works as a global option (on OverlaysManager level) now).

Copy link
Member

@tlouisse tlouisse Mar 8, 2024

Choose a reason for hiding this comment

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

Maybe we can solve this in a different way (without _blocksEscKeyHandler)?
You could for instance check whether the esc event came from a child in the dom. If so, and we have closeOnEsc and not closeOnOutsideEsc, we should not close ourselves.

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.

None yet

2 participants