Skip to content

Commit

Permalink
feat(Dropdown): Added support for setting height for dropdown (#10149)
Browse files Browse the repository at this point in the history
* feat(Dropdown): Added support for setting height for dropdown

* apply isScrollable to menu if maxMenuHeight or menuHeight is defined
  • Loading branch information
tlabaj authored Mar 26, 2024
1 parent 908f1fb commit 9db5e7b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/react-core/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export interface DropdownProps extends MenuProps, OUIAProps {
zIndex?: number;
/** Additional properties to pass to the Popper */
popperProps?: DropdownPopperProps;
/** Height of the dropdown menu */
menuHeight?: string;
/** Maximum height of dropdown menu */
maxMenuHeight?: string;
}

const DropdownBase: React.FunctionComponent<DropdownProps> = ({
Expand All @@ -83,6 +87,8 @@ const DropdownBase: React.FunctionComponent<DropdownProps> = ({
zIndex = 9999,
popperProps,
onOpenChangeKeys = ['Escape', 'Tab'],
menuHeight,
maxMenuHeight,
...props
}: DropdownProps) => {
const localMenuRef = React.useRef<HTMLDivElement>();
Expand Down Expand Up @@ -138,6 +144,8 @@ const DropdownBase: React.FunctionComponent<DropdownProps> = ({
};
}, [isOpen, menuRef, toggleRef, onOpenChange, onOpenChangeKeys]);

const scrollable = maxMenuHeight !== undefined || menuHeight !== undefined || isScrollable;

const menu = (
<Menu
className={css(className)}
Expand All @@ -147,11 +155,13 @@ const DropdownBase: React.FunctionComponent<DropdownProps> = ({
shouldFocusToggleOnSelect && toggleRef.current.focus();
}}
isPlain={isPlain}
isScrollable={isScrollable}
isScrollable={scrollable}
{...props}
{...ouiaProps}
>
<MenuContent>{children}</MenuContent>
<MenuContent menuHeight={menuHeight} maxMenuHeight={maxMenuHeight}>
{children}
</MenuContent>
</Menu>
);
return (
Expand Down

0 comments on commit 9db5e7b

Please sign in to comment.