Skip to content
Merged
Changes from all 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
32 changes: 22 additions & 10 deletions packages/react-core/src/next/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ export interface DropdownProps extends MenuProps, OUIAProps {
ouiaSafe?: boolean;
/** z-index of the dropdown menu */
zIndex?: number;
/** The container to append the dropdown to. Defaults to 'inline'.
* If your dropdown is being cut off you can append it to an element higher up the DOM tree.
* Some examples:
* appendTo="inline"
* appendTo={() => document.body}
* appendTo={document.getElementById('target')}
*/
appendTo?: HTMLElement | (() => HTMLElement) | 'inline';
}

const DropdownBase: React.FunctionComponent<DropdownProps> = ({
Expand All @@ -48,6 +56,7 @@ const DropdownBase: React.FunctionComponent<DropdownProps> = ({
ouiaId,
ouiaSafe = true,
zIndex = 9999,
appendTo = 'inline',
...props
}: DropdownProps) => {
const localMenuRef = React.useRef<HTMLDivElement>();
Expand Down Expand Up @@ -109,21 +118,24 @@ const DropdownBase: React.FunctionComponent<DropdownProps> = ({
} as React.CSSProperties
})}
{...props}
{...ouiaProps}
>
<MenuContent>{children}</MenuContent>
</Menu>
);
return (
<div ref={containerRef} {...ouiaProps}>
<Popper
trigger={toggle(toggleRef)}
removeFindDomNode
popper={menu}
appendTo={containerRef.current || undefined}
isVisible={isOpen}
zIndex={zIndex}
/>
const popperProps = {
trigger: toggle(toggleRef),
removeFindDomNode: true,
popper: menu,
isVisible: isOpen,
zIndex
};
return appendTo === 'inline' ? (
<div ref={containerRef}>
<Popper {...popperProps} appendTo={containerRef.current || undefined} />
</div>
) : (
<Popper {...popperProps} appendTo={appendTo} />
);
};

Expand Down