fix(Drawer): prevent nested drawer mask stacking#666
Merged
Conversation
xanderantoniadis
approved these changes
Jul 13, 2026
xanderantoniadis
left a comment
Collaborator
There was a problem hiding this comment.
Solid solution! good job 👏
|
🎉 This PR is included in version 6.7.6 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When multiple
<Drawer>components are open simultaneously (e.g. opening a drawer from within another drawer), each instance independently renders its own semi-transparent backdrop mask. The masks stack on top of each other, causing the background to become progressively darker with each additional drawer. Navigating back and forth compounds the issue that the accumulated backdrop layers are never cleaned up, making the left side of the screen increasingly opaque.Changes
useDrawerStackPositionhook: Maintains a module-levelopenDrawerStackarray tracking all open drawer instances byuseId(). UsesuseSyncExternalStorefor tear-free reads anduseLayoutEffectfor synchronous registration/cleanup. Only the drawer at index0(the first opened) returnsisBottomMostOpenDrawer: true— all subsequent drawers render a transparent mask instead.showMaskprop fromDrawerProps: Mask visibility is now fully automatic based on stack position — consumers no longer need to passshowMask. TheMaskcomponent acceptsvisible(controls background opacity) andonClick(optional close handler) instead of the previousonClose.shouldRenderMask = closeOnOutsideClick || isBottomMostOpenDrawerensures the mask element exists when needed for click interception or backdrop display.shouldShowVisibleMask = isBottomMostOpenDrawercontrols whether the backdrop is opaque or transparent. WhencloseOnOutsideClickisfalse, the mask renders (visible if bottom-most) but doesn't fire the close callback.maskContainerstyle converted to function: Now accepts avisibleboolean — rendersrgba(0, 0, 0, 0.45)when visible,transparentotherwise. Addeddata-mask-visibleattribute for test assertions.DRAWER_ROOT_IDconstant from inline string toconstants.ts.useDrawerStackPosition.test.ts): Covers single drawer, nested drawers, 3-deep nesting, closing top/bottom drawer promotion, and unmount while open.Drawer.test.tsx: Covers visible mask withcloseOnOutsideClick=false, disabled outside click, single visible mask with multiple drawers, and mask promotion on close.Fixes