From 1f49d480a80f6bb16982bf95bda8045209d9933b Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Tue, 22 Aug 2023 16:11:18 +0100 Subject: [PATCH] Drawer: Clicking a `Select` arrow within a `Drawer` no longer causes it to close (#73557) ensure drawer doesn't close when clicking dropdown arrow --- .../src/components/Drawer/Drawer.tsx | 43 +++++++++++++++---- .../core/components/AppChrome/AppChrome.tsx | 7 ++- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/packages/grafana-ui/src/components/Drawer/Drawer.tsx b/packages/grafana-ui/src/components/Drawer/Drawer.tsx index ea2f7394bf2..a88003394b9 100644 --- a/packages/grafana-ui/src/components/Drawer/Drawer.tsx +++ b/packages/grafana-ui/src/components/Drawer/Drawer.tsx @@ -4,7 +4,6 @@ import { FocusScope } from '@react-aria/focus'; import { useOverlay } from '@react-aria/overlays'; import RcDrawer from 'rc-drawer'; import React, { ReactNode, useEffect } from 'react'; -import { useClickAway } from 'react-use'; import { GrafanaTheme2 } from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; @@ -73,8 +72,6 @@ export function Drawer({ // Adds body class while open so the toolbar nav can hide some actions while drawer is open useBodyClassWhileOpen(); - // Close when we click outside mask (topnav) but only if closeOnMaskClick is true - useClickAway(overlayRef, closeOnMaskClick ? onClose : doNothing); // Apply size styles (unless deprecated width prop is used) const rootClass = cx(styles.drawer, !width && styles.sizes[size]); @@ -143,8 +140,6 @@ export function Drawer({ ); } -function doNothing() {} - function useBodyClassWhileOpen() { useEffect(() => { if (!document.body) { @@ -170,11 +165,15 @@ const getStyles = (theme: GrafanaTheme2) => { }), drawer: css({ '.main-view &': { - top: '81px', + top: 81, }, '.main-view--search-bar-hidden &': { - top: '41px', + top: 41, + }, + + '.main-view--chrome-hidden &': { + top: 0, }, '.rc-drawer-content-wrapper': { @@ -232,9 +231,35 @@ const getStyles = (theme: GrafanaTheme2) => { }, }, }), + // we want the mask itself to span the whole page including the top bar + // this ensures trying to click something in the top bar will close the drawer correctly + // but we don't want the backdrop styling to apply over the top bar as it looks weird + // instead have a child pseudo element to apply the backdrop styling below the top bar mask: css({ - backgroundColor: `${theme.components.overlay.background} !important`, - backdropFilter: 'blur(1px)', + backgroundColor: 'transparent', + position: 'fixed', + + '&:before': { + backgroundColor: `${theme.components.overlay.background} !important`, + backdropFilter: 'blur(1px)', + bottom: 0, + content: '""', + left: 0, + position: 'fixed', + right: 0, + + '.main-view &': { + top: 81, + }, + + '.main-view--search-bar-hidden &': { + top: 41, + }, + + '.main-view--chrome-hidden &': { + top: 0, + }, + }, }), maskMotion: css({ '&-appear': { diff --git a/public/app/core/components/AppChrome/AppChrome.tsx b/public/app/core/components/AppChrome/AppChrome.tsx index aa0616d4d44..d803f3fc40e 100644 --- a/public/app/core/components/AppChrome/AppChrome.tsx +++ b/public/app/core/components/AppChrome/AppChrome.tsx @@ -34,7 +34,12 @@ export function AppChrome({ children }: Props) { // doesn't get re-mounted when chromeless goes from true to false. return ( -
+
{!state.chromeless && ( <>