From eba0390502f39276f657f21e4270b2b2008c1df0 Mon Sep 17 00:00:00 2001 From: Tobias Skarhed <1438972+tskarhed@users.noreply.github.com> Date: Sun, 9 Feb 2020 12:50:01 +0100 Subject: [PATCH] New Select: Fix the overflow issue and menu positioning (#22039) * Fix the overflow issue and menu positioning * Add portal as a property --- .../components/Forms/Select/ButtonSelect.tsx | 10 +++--- .../components/Forms/Select/Select.story.tsx | 34 ++++++++++++++++--- .../src/components/Forms/Select/Select.tsx | 8 ++--- .../Forms/Select/SelectBase.test.tsx | 12 +++---- .../components/Forms/Select/SelectBase.tsx | 15 ++++++++ .../components/Forms/Select/SelectMenu.tsx | 5 +-- .../Forms/Select/getSelectStyles.ts | 2 +- .../components/Select/ButtonSelect.story.tsx | 2 +- 8 files changed, 66 insertions(+), 22 deletions(-) diff --git a/packages/grafana-ui/src/components/Forms/Select/ButtonSelect.tsx b/packages/grafana-ui/src/components/Forms/Select/ButtonSelect.tsx index 01b772cc1bf..eca501dec5b 100644 --- a/packages/grafana-ui/src/components/Forms/Select/ButtonSelect.tsx +++ b/packages/grafana-ui/src/components/Forms/Select/ButtonSelect.tsx @@ -17,9 +17,10 @@ interface ButtonSelectProps extends Omit, 'renderControl interface SelectButtonProps extends Omit { icon?: IconType; isOpen?: boolean; + innerRef: any; } -const SelectButton: React.FC = ({ icon, children, isOpen, ...buttonProps }) => { +const SelectButton: React.FC = ({ icon, children, isOpen, innerRef, ...buttonProps }) => { const theme = useTheme(); const styles = { wrapper: css` @@ -42,7 +43,7 @@ const SelectButton: React.FC = ({ icon, children, isOpen, ... const buttonIcon = `fa fa-${icon}`; const caretIcon = isOpen ? 'caret-up' : 'caret-down'; return ( - ; - }} + portal={document.body} + renderControl={React.forwardRef(({ isOpen, value, ...otherProps }, ref) => { + return ( + + ); + })} {...getDynamicProps()} /> ); }; +export const autoMenuPlacement = () => { + const [value, setValue] = useState>(); + + return ( + <> +
+