Modal: Fix restore focus behavior (#43749)
* Modal: Fix restore focus behavior * Use OverlayContainer Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
This commit is contained in:
co-authored by
Ashley Harrison
parent
8717bc7ef4
commit
e7f1e11229
@@ -1,5 +1,4 @@
|
|||||||
import React, { PropsWithChildren, useCallback, useEffect } from 'react';
|
import React, { PropsWithChildren, useCallback, useEffect } from 'react';
|
||||||
import { Portal } from '../Portal/Portal';
|
|
||||||
import { cx } from '@emotion/css';
|
import { cx } from '@emotion/css';
|
||||||
import { useTheme2 } from '../../themes';
|
import { useTheme2 } from '../../themes';
|
||||||
import { IconName } from '../../types';
|
import { IconName } from '../../types';
|
||||||
@@ -8,6 +7,7 @@ import { ModalHeader } from './ModalHeader';
|
|||||||
import { IconButton } from '../IconButton/IconButton';
|
import { IconButton } from '../IconButton/IconButton';
|
||||||
import { HorizontalGroup } from '../Layout/Layout';
|
import { HorizontalGroup } from '../Layout/Layout';
|
||||||
import { FocusScope } from '@react-aria/focus';
|
import { FocusScope } from '@react-aria/focus';
|
||||||
|
import { OverlayContainer } from '@react-aria/overlays';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
/** @deprecated no longer used */
|
/** @deprecated no longer used */
|
||||||
@@ -71,7 +71,7 @@ export function Modal(props: PropsWithChildren<Props>) {
|
|||||||
const headerClass = cx(styles.modalHeader, typeof title !== 'string' && styles.modalHeaderWithTabs);
|
const headerClass = cx(styles.modalHeader, typeof title !== 'string' && styles.modalHeaderWithTabs);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Portal>
|
<OverlayContainer>
|
||||||
<div
|
<div
|
||||||
className={styles.modalBackdrop}
|
className={styles.modalBackdrop}
|
||||||
onClick={onClickBackdrop || (closeOnBackdropClick ? onDismiss : undefined)}
|
onClick={onClickBackdrop || (closeOnBackdropClick ? onDismiss : undefined)}
|
||||||
@@ -88,7 +88,7 @@ export function Modal(props: PropsWithChildren<Props>) {
|
|||||||
<div className={cx(styles.modalContent, contentClassName)}>{children}</div>
|
<div className={cx(styles.modalContent, contentClassName)}>{children}</div>
|
||||||
</div>
|
</div>
|
||||||
</FocusScope>
|
</FocusScope>
|
||||||
</Portal>
|
</OverlayContainer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ export const getModalStyles = stylesFactory((theme: GrafanaTheme2) => {
|
|||||||
`,
|
`,
|
||||||
modalBackdrop: css`
|
modalBackdrop: css`
|
||||||
position: fixed;
|
position: fixed;
|
||||||
|
z-index: ${theme.zIndex.modalBackdrop};
|
||||||
top: 0;
|
top: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user