Skip to content

Commit 4dd651f

Browse files
committed
fix(select): set portal target to on mount
1 parent f06779c commit 4dd651f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Diff for: src/components/Select/Select.tsx

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { FC, useContext, ComponentProps, ComponentType } from 'react';
1+
import {
2+
FC,
3+
useContext,
4+
useState,
5+
useEffect,
6+
ComponentProps,
7+
ComponentType,
8+
} from 'react';
29
import ReactSelect, {
310
components,
411
OptionsType,
@@ -82,6 +89,13 @@ export const Select: FC<SelectProps> = ({
8289
...props
8390
}) => {
8491
const currentTheme = useContext(ThemeContext);
92+
const [menuPortalTarget, setMenuPortalTarget] = useState<
93+
HTMLElement | undefined
94+
>();
95+
96+
useEffect(() => {
97+
setMenuPortalTarget(document.body);
98+
}, []);
8599

86100
// @TODO: properly type this function
87101
const handleChange = (e?: any) => {
@@ -124,7 +138,7 @@ export const Select: FC<SelectProps> = ({
124138
onChange={handleChange}
125139
noIcon={noIcon}
126140
menuPlacement="auto"
127-
menuPortalTarget={document.body}
141+
menuPortalTarget={menuPortalTarget}
128142
backspaceRemovesValue={false}
129143
{...props}
130144
/>

0 commit comments

Comments
 (0)