-
Notifications
You must be signed in to change notification settings - Fork 23
fix(menu): Keep persistent elements interactive while a modal menu is open #1062
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,11 +148,29 @@ interface MenuListProps | |
| extends Omit<AriakitMenuProps, 'store' | 'className'>, | ||
| ObfuscatedClassName {} | ||
|
|
||
| /** | ||
| * Selector for elements that should remain interactive while a modal menu is open. | ||
| * | ||
| * A modal `MenuList` marks the entire element tree outside of it as `inert`, which removes those | ||
| * elements from hit-testing. On desktop apps (e.g. Electron) this breaks the native window | ||
| * drag region (`-webkit-app-region: drag`) of the title bar, since `inert` elements no longer | ||
| * receive the OS drag gesture. Marking such elements with `data-reactist-persist` keeps them | ||
| * interactive while the menu stays modal in every other respect. | ||
| */ | ||
| const PERSISTENT_ELEMENTS_SELECTOR = '[data-reactist-persist]' | ||
|
|
||
| function getPersistentElementsDefault(): Element[] { | ||
| if (typeof document === 'undefined') { | ||
| return [] | ||
| } | ||
| return Array.from(document.querySelectorAll(PERSISTENT_ELEMENTS_SELECTOR)) | ||
| } | ||
|
|
||
| /** | ||
| * The dropdown menu itself, containing a list of menu items. | ||
| */ | ||
| const MenuList = React.forwardRef<HTMLDivElement, MenuListProps>(function MenuList( | ||
| { exceptionallySetClassName, modal = true, flip, ...props }, | ||
| { exceptionallySetClassName, modal = true, flip, getPersistentElements, ...props }, | ||
| ref, | ||
| ) { | ||
| const { menuStore, getAnchorRect } = React.useContext(MenuContext) | ||
|
|
@@ -164,6 +182,16 @@ const MenuList = React.forwardRef<HTMLDivElement, MenuListProps>(function MenuLi | |
|
|
||
| const isOpen = menuStore.useState('open') | ||
|
|
||
| const mergedGetPersistentElements = React.useCallback( | ||
| function mergedGetPersistentElements(): Element[] { | ||
| const consumerElements = getPersistentElements | ||
| ? Array.from(getPersistentElements()) | ||
| : [] | ||
| return [...getPersistentElementsDefault(), ...consumerElements] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 P2 This makes every modal |
||
| }, | ||
| [getPersistentElements], | ||
| ) | ||
|
|
||
| return isOpen ? ( | ||
| <Portal preserveTabOrder> | ||
| <AriakitMenu | ||
|
|
@@ -175,6 +203,7 @@ const MenuList = React.forwardRef<HTMLDivElement, MenuListProps>(function MenuLi | |
| className={classNames('reactist_menulist', exceptionallySetClassName)} | ||
| getAnchorRect={getAnchorRect ?? undefined} | ||
| modal={modal} | ||
| getPersistentElements={mergedGetPersistentElements} | ||
| flip={flip ?? (isSubMenu ? 'left bottom' : undefined)} | ||
| /> | ||
| </Portal> | ||
|
|
||
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.
🟡 P2
MenuListPropsinherits Ariakit’sgetPersistentElements, so callers will expect this prop to define the complete persistent-element set. Merging the default selector here turns it into an append-only hook: once an app addsdata-reactist-persistanywhere, everyMenuListwill keep those elements interactive and a caller can’t opt back into strict modal behavior for a specific menu. That’s a surprising contract change for a pass-through Ariakit prop. Consider applying the default only whengetPersistentElementsis unset, or introducing a separate Reactist prop for the title-bar escape hatch.