diff --git a/packages/grafana-ui/src/components/Drawer/Drawer.tsx b/packages/grafana-ui/src/components/Drawer/Drawer.tsx index 674470cff95..4502d7ddad2 100644 --- a/packages/grafana-ui/src/components/Drawer/Drawer.tsx +++ b/packages/grafana-ui/src/components/Drawer/Drawer.tsx @@ -7,6 +7,8 @@ import { selectors } from '@grafana/e2e-selectors'; import { CustomScrollbar } from '../CustomScrollbar/CustomScrollbar'; import { IconButton } from '../IconButton/IconButton'; import { stylesFactory, useTheme2 } from '../../themes'; +import { FocusScope } from '@react-aria/focus'; +import { useOverlay } from '@react-aria/overlays'; export interface Props { children: ReactNode; @@ -98,6 +100,13 @@ export const Drawer: FC = ({ const [isExpanded, setIsExpanded] = useState(false); const [isOpen, setIsOpen] = useState(false); const currentWidth = isExpanded ? '100%' : width; + const overlayRef = React.useRef(null); + const { overlayProps } = useOverlay( + { + isDismissable: true, + }, + overlayRef + ); // RcDrawer v4.x needs to be mounted in advance for animations to play. useEffect(() => { @@ -122,46 +131,48 @@ export const Drawer: FC = ({ : selectors.components.Drawer.General.title('no title') } > - {typeof title === 'string' && ( -
-
- {expandable && !isExpanded && ( + + {typeof title === 'string' && ( +
+
+ {expandable && !isExpanded && ( + setIsExpanded(true)} + surface="header" + aria-label={selectors.components.Drawer.General.expand} + /> + )} + {expandable && isExpanded && ( + setIsExpanded(false)} + surface="header" + aria-label={selectors.components.Drawer.General.contract} + /> + )} setIsExpanded(true)} + onClick={onClose} surface="header" - aria-label={selectors.components.Drawer.General.expand} + aria-label={selectors.components.Drawer.General.close} /> - )} - {expandable && isExpanded && ( - setIsExpanded(false)} - surface="header" - aria-label={selectors.components.Drawer.General.contract} - /> - )} - -
-
-

{title}

- {typeof subtitle === 'string' &&
{subtitle}
} - {typeof subtitle !== 'string' && subtitle} +
+
+

{title}

+ {typeof subtitle === 'string' &&
{subtitle}
} + {typeof subtitle !== 'string' && subtitle} +
+ )} + {typeof title !== 'string' && title} +
+ {!scrollableContent ? children : {children}}
- )} - {typeof title !== 'string' && title} -
- {!scrollableContent ? children : {children}} -
+
); };