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

[Popper] Fix regression when an occluded submenu stays visible even with enabled hideWhenDetached flag #3237

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .yarn/versions/588134e5.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
releases:
"@radix-ui/react-context-menu": patch
"@radix-ui/react-dropdown-menu": patch
"@radix-ui/react-hover-card": patch
"@radix-ui/react-menu": patch
"@radix-ui/react-menubar": patch
"@radix-ui/react-popover": patch
"@radix-ui/react-popper": patch
"@radix-ui/react-select": patch
"@radix-ui/react-tooltip": patch

declined:
- primitives
42 changes: 29 additions & 13 deletions packages/react/menu/src/Menu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const Submenus = () => {
const [open4, setOpen4] = React.useState(false);
const [rtl, setRtl] = React.useState(false);
const [animated, setAnimated] = React.useState(false);
const [scrollable, setScrollable] = React.useState(false);

React.useEffect(() => {
if (rtl) {
Expand Down Expand Up @@ -64,12 +65,38 @@ export const Submenus = () => {
/>
Animated
</label>
<label>
<input
type="checkbox"
checked={scrollable}
onChange={(event) => setScrollable(event.currentTarget.checked)}
/>
Scrollable
</label>
</div>
<MenuWithAnchor>
<MenuWithAnchor style={scrollable ? { overflow: 'scroll', height: 100 } : undefined}>
nikita-miro marked this conversation as resolved.
Show resolved Hide resolved
<Menu.Item className={itemClass()} onSelect={() => window.alert('undo')}>
Undo
</Menu.Item>
<Submenu open={open1} onOpenChange={setOpen1} animated={animated}>

<Menu.Separator className={separatorClass()} />
<Menu.Item className={itemClass()} disabled onSelect={() => window.alert('cut')}>
Cut
</Menu.Item>
<Menu.Item className={itemClass()} onSelect={() => window.alert('copy')}>
Copy
</Menu.Item>
<Menu.Item className={itemClass()} onSelect={() => window.alert('paste')}>
Paste
</Menu.Item>

<Menu.Separator className={separatorClass()} />
<Submenu
open={open1}
onOpenChange={setOpen1}
animated={animated}
hideWhenDetached={scrollable}
>
<Menu.Item className={itemClass()} disabled>
Disabled
</Menu.Item>
Expand Down Expand Up @@ -125,17 +152,6 @@ export const Submenus = () => {
Three
</Menu.Item>
</Submenu>

<Menu.Separator className={separatorClass()} />
<Menu.Item className={itemClass()} disabled onSelect={() => window.alert('cut')}>
Cut
</Menu.Item>
<Menu.Item className={itemClass()} onSelect={() => window.alert('copy')}>
Copy
</Menu.Item>
<Menu.Item className={itemClass()} onSelect={() => window.alert('paste')}>
Paste
</Menu.Item>
</MenuWithAnchor>
</DirectionProvider>
);
Expand Down
12 changes: 8 additions & 4 deletions packages/react/popper/src/Popper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const PopperContent = React.forwardRef<PopperContentElement, PopperContentProps>
alignOffset = 0,
arrowPadding = 0,
avoidCollisions = true,
collisionBoundary = [],
collisionBoundary,
nikita-miro marked this conversation as resolved.
Show resolved Hide resolved
collisionPadding: collisionPaddingProp = 0,
sticky = 'partial',
hideWhenDetached = false,
Expand All @@ -161,12 +161,16 @@ const PopperContent = React.forwardRef<PopperContentElement, PopperContentProps>
? collisionPaddingProp
: { top: 0, right: 0, bottom: 0, left: 0, ...collisionPaddingProp };

const boundary = Array.isArray(collisionBoundary) ? collisionBoundary : [collisionBoundary];
const hasExplicitBoundaries = boundary.length > 0;
const boundary = collisionBoundary
? Array.isArray(collisionBoundary)
? collisionBoundary
: [collisionBoundary]
: undefined;
const hasExplicitBoundaries = boundary !== undefined && boundary.length > 0;

const detectOverflowOptions = {
padding: collisionPadding,
boundary: boundary.filter(isNotNull),
boundary: boundary ? boundary.filter(isNotNull) : undefined,
// with `strategy: 'fixed'`, this is the only way to get it to respect boundaries
altBoundary: hasExplicitBoundaries,
};
Expand Down