Skip to content

Commit a46623e

Browse files
committed
fix(popover/menu): scrollbar now appears when content exceeds maximum size
When there were many options in a Select, a scrollbar did not appear. Just as it did not appear in a Menu, whose max-height was not respected. With this commit, these problems have been solved.
1 parent 2e9501b commit a46623e

4 files changed

Lines changed: 27 additions & 3 deletions

File tree

packages/actify/src/components/Menus/MenuPopover.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export interface PopoverProps extends Omit<AriaPopoverProps, 'children'> {
1717
}
1818

1919
const MenuPopover = ({ children, ...props }: PopoverProps) => {
20+
const dialogRef = React.useRef<HTMLDivElement>(null);
21+
22+
const onAnimationComplete = React.useCallback(() => {
23+
dialogRef.current?.classList.add(styles['open']);
24+
}, [dialogRef])
25+
2026
// make the width of the popover the same as the reference element
2127
if (props.referenceWidth) {
2228
props.style = {
@@ -33,14 +39,16 @@ const MenuPopover = ({ children, ...props }: PopoverProps) => {
3339
overflow: 'hidden'
3440
}}
3541
animate={{
36-
height: 'auto'
42+
height: 'auto',
43+
maxHeight: 'inherit',
3744
}}
3845
transition={{
3946
duration: 0.3
4047
}}
48+
onAnimationComplete={onAnimationComplete}
4149
>
4250
<OverlayArrow className={styles['underlay']} />
43-
<Dialog aria-label="dialog" className={styles['dialog']}>
51+
<Dialog aria-label="dialog" className={styles['dialog']} ref={dialogRef}>
4452
{children}
4553
</Dialog>
4654
</motion.div>

packages/actify/src/components/Menus/menu-popover.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@
2828
);
2929
scrollbar-width: inherit;
3030
}
31+
32+
.dialog.open {
33+
overflow: auto;
34+
}

packages/actify/src/components/Popover/Popover.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ const Popover = (props: PopoverProps & React.RefAttributes<HTMLElement>) => {
8383
} as React.CSSProperties
8484
}
8585

86+
// apply a class that enables scrolling if necessary
87+
const onAnimationComplete = React.useCallback(() => {
88+
popoverRef.current?.classList.add(styles['open']);
89+
}, [popoverRef])
90+
8691
return (
8792
<Overlay>
8893
<div {...underlayProps} className={styles['underlay']} />
@@ -91,8 +96,10 @@ const Popover = (props: PopoverProps & React.RefAttributes<HTMLElement>) => {
9196
{...popoverProps}
9297
className={styles['popover']}
9398
initial={{
94-
height: 0
99+
height: 0,
100+
overflow: 'hidden'
95101
}}
102+
onAnimationComplete={onAnimationComplete}
96103
animate={{
97104
height: 'auto'
98105
}}

packages/actify/src/components/Popover/popover.module.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
);
2424
scrollbar-width: inherit;
2525
}
26+
2627
.popover > ul {
2728
overflow: hidden;
2829
}
30+
31+
.popover.open > ul {
32+
overflow: auto;
33+
}

0 commit comments

Comments
 (0)