-
Notifications
You must be signed in to change notification settings - Fork 506
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
Conversation
|
size-limit report 📦
|
for (let i = handlers.length - 1; i >= 0; --i) { | ||
handlers[i](event) | ||
if (!event.defaultPrevented) { | ||
for (const handler of Object.values(registry).reverse()) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 😅
src/hooks/useOverlay.tsx
Outdated
@@ -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 */ |
There was a problem hiding this comment.
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?
/** We only want one overlay to close at a time */ | |
// We only want one overlay to close at a time |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 ❤️
Forgot to include it in the PR
Fixes #1854
useOnEscapePress
are triggering allescape
events globally #1854)Does not fix in this PR, need to experiment more: