Skip to content

Commit

Permalink
fix(select): set portal target to on mount
Browse files Browse the repository at this point in the history
  • Loading branch information
honarpour committed Dec 23, 2021
1 parent f06779c commit 4dd651f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/components/Select/Select.tsx
@@ -1,4 +1,11 @@
import { FC, useContext, ComponentProps, ComponentType } from 'react';
import {
FC,
useContext,
useState,
useEffect,
ComponentProps,
ComponentType,
} from 'react';
import ReactSelect, {
components,
OptionsType,
Expand Down Expand Up @@ -82,6 +89,13 @@ export const Select: FC<SelectProps> = ({
...props
}) => {
const currentTheme = useContext(ThemeContext);
const [menuPortalTarget, setMenuPortalTarget] = useState<
HTMLElement | undefined
>();

useEffect(() => {
setMenuPortalTarget(document.body);
}, []);

// @TODO: properly type this function
const handleChange = (e?: any) => {
Expand Down Expand Up @@ -124,7 +138,7 @@ export const Select: FC<SelectProps> = ({
onChange={handleChange}
noIcon={noIcon}
menuPlacement="auto"
menuPortalTarget={document.body}
menuPortalTarget={menuPortalTarget}
backspaceRemovesValue={false}
{...props}
/>
Expand Down

0 comments on commit 4dd651f

Please sign in to comment.