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

Escape on nested Overlays #1861

Merged
merged 11 commits into from
Feb 15, 2022
Merged

Escape on nested Overlays #1861

merged 11 commits into from
Feb 15, 2022

Conversation

siddharthkp
Copy link
Member

@siddharthkp siddharthkp commented Feb 11, 2022

Fixes #1854

Does not fix in this PR, need to experiment more:

@changeset-bot
Copy link

changeset-bot bot commented Feb 11, 2022

⚠️ No Changeset found

Latest commit: bc96a9b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions
Copy link
Contributor

github-actions bot commented Feb 11, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 62.6 KB (-0.03% 🔽)
dist/browser.umd.js 63 KB (-0.01% 🔽)

@siddharthkp siddharthkp added the skip changeset This change does not need a changelog label Feb 11, 2022
@siddharthkp siddharthkp self-assigned this Feb 11, 2022
@siddharthkp siddharthkp changed the title Escape on Overlays Escape on nested Overlays Feb 14, 2022
@siddharthkp siddharthkp marked this pull request as ready for review February 14, 2022 16:36
@siddharthkp siddharthkp requested a review from a team February 14, 2022 16:36
for (let i = handlers.length - 1; i >= 0; --i) {
handlers[i](event)
if (!event.defaultPrevented) {
for (const handler of Object.values(registry).reverse()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the order of Object.values(registry) consistent/predictable?

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make more sense to push and pop from a stack (array)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep! I found it more consistent than an array implementation I tried to build myself.

setEditing(false)
setTitle(title)
event.preventDefault() // prevent Overlay from closing, this is what we recommend
// event.stopPropagation() // this also works and feels nicer to use
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should update this comment to explain that event.stopPropagation() doesn't work here yet

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case, it does work though because the order of handlers is predictable 😅

@@ -29,6 +29,12 @@ export const useOverlay = ({
const overlayRef = useProvidedRefOrCreate<HTMLDivElement>(_overlayRef)
useOpenAndCloseFocus({containerRef: overlayRef, returnFocusRef, initialFocusRef, preventFocusOnOpen})
useOnOutsideClick({containerRef: overlayRef, ignoreClickRefs, onClickOutside})
useOnEscapePress(onEscape)

/** We only want one overlay to close at a time */
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: do we need a JSDoc-style comment here?

Suggested change
/** We only want one overlay to close at a time */
// We only want one overlay to close at a time

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, not sure what I had here. fixed now.

Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

This was a tricky bug. Nice fix ✨ Just left a few non-blocking comments

I love that we're building real-world examples in our storybook ❤️

@siddharthkp siddharthkp merged commit 11a76b3 into main Feb 15, 2022
@siddharthkp siddharthkp deleted the siddharthkp/nested-overlay-escape branch February 15, 2022 14:09
siddharthkp added a commit that referenced this pull request Feb 15, 2022
Forgot to include it in the PR
siddharthkp added a commit that referenced this pull request Feb 17, 2022
Forgot to include it in the PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
react skip changeset This change does not need a changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Element-bound events with useOnEscapePress are triggering all escape events globally
2 participants