Skip to content

Commit 9340381

Browse files
authoredSep 21, 2023
feat(select next): add appendTo (#9562)

File tree

1 file changed

+20
-9
lines changed
  • packages/react-core/src/next/components/Select

1 file changed

+20
-9
lines changed
 

‎packages/react-core/src/next/components/Select/Select.tsx

+20-9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ export interface SelectProps extends MenuProps, OUIAProps {
3030
zIndex?: number;
3131
/** @beta Determines the accessible role of the select. For a checkbox select pass in "menu". */
3232
role?: string;
33+
/** The container to append the select to. Defaults to 'inline'.
34+
* If your select is being cut off you can append it to an element higher up the DOM tree.
35+
* Some examples:
36+
* appendTo="inline"
37+
* appendTo={() => document.body}
38+
* appendTo={document.getElementById('target')}
39+
*/
40+
appendTo?: HTMLElement | (() => HTMLElement) | 'inline';
3341
}
3442

3543
const SelectBase: React.FunctionComponent<SelectProps & OUIAProps> = ({
@@ -45,6 +53,7 @@ const SelectBase: React.FunctionComponent<SelectProps & OUIAProps> = ({
4553
innerRef,
4654
zIndex = 9999,
4755
role = 'listbox',
56+
appendTo = 'inline',
4857
...props
4958
}: SelectProps & OUIAProps) => {
5059
const localMenuRef = React.useRef<HTMLDivElement>();
@@ -115,17 +124,19 @@ const SelectBase: React.FunctionComponent<SelectProps & OUIAProps> = ({
115124
<MenuContent>{children}</MenuContent>
116125
</Menu>
117126
);
118-
return (
127+
const popperProps = {
128+
trigger: toggle(toggleRef),
129+
removeFindDomNode: true,
130+
popper: menu,
131+
isVisible: isOpen,
132+
zIndex
133+
};
134+
return appendTo === 'inline' ? (
119135
<div ref={containerRef}>
120-
<Popper
121-
trigger={toggle(toggleRef)}
122-
removeFindDomNode
123-
popper={menu}
124-
appendTo={containerRef.current || undefined}
125-
isVisible={isOpen}
126-
zIndex={zIndex}
127-
/>
136+
<Popper {...popperProps} appendTo={containerRef.current || undefined} />
128137
</div>
138+
) : (
139+
<Popper {...popperProps} appendTo={appendTo} />
129140
);
130141
};
131142

0 commit comments

Comments
 (0)
Please sign in to comment.