Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Gdgt 2575 replace deprecated modal component (#75563)

Egor Grushin3153af073521
diff --git a/.storybook/preview.tsx b/.storybook/preview.tsx
index c248a5e2c24..6c0c247baa5 100644
--- a/.storybook/preview.tsx
+++ b/.storybook/preview.tsx
@@ -1,6 +1,9 @@
import React, { useEffect, useMemo } from "react";
import { createPortal } from "react-dom";
+import { baseStyle, rootStyle } from "metabase/css/core/base.styled";
+import { defaultFontFiles } from "metabase/css/core/fonts.styled";
+import { getMetabaseCssVariables } from "metabase/styled-components/theme/css-variables";
import { PortalContainer, ThemeProvider } from "metabase/ui";
// @ts-expect-error: See metabase/utils/delay
@@ -15,13 +18,11 @@ require("metabase/utils/dayjs");
import "@mantine/core/styles.css";
import "@mantine/dates/styles.css";
+import { OverlayStackProvider } from "metabase/ui/components/overlays/overlay-stack";
import { EmotionCacheProvider } from "metabase/ui/components/theme/EmotionCacheProvider";
-import { getMetabaseCssVariables } from "metabase/styled-components/theme/css-variables";
import { Global, css, useTheme } from "@emotion/react";
-import { baseStyle, rootStyle } from "metabase/css/core/base.styled";
-import { defaultFontFiles } from "metabase/css/core/fonts.styled";
import { saveDomImageStyles } from "metabase/visualizations/lib/image-exports";
import { initialize, mswLoader } from "msw-storybook-addon";
@@ -137,12 +138,14 @@ const decorators = [
return (
<EmotionCacheProvider>
- <ThemeProvider resolvedColorScheme={resolvedColorScheme}>
- <Global styles={globalStyles} />
- <CssVariables />
- {createPortal(<PortalContainer />, document.body)}
- <Story />
- </ThemeProvider>
+ <OverlayStackProvider>
+ <ThemeProvider resolvedColorScheme={resolvedColorScheme}>
+ <Global styles={globalStyles} />
+ <CssVariables />
+ {createPortal(<PortalContainer />, document.body)}
+ <Story />
+ </ThemeProvider>
+ </OverlayStackProvider>
</EmotionCacheProvider>
);
},
diff --git a/e2e/support/helpers/e2e-embedding-sdk-interactive-question-helpers.tsx b/e2e/support/helpers/e2e-embedding-sdk-interactive-question-helpers.tsx
index 1e960747515..837d1d45e6a 100644
--- a/e2e/support/helpers/e2e-embedding-sdk-interactive-question-helpers.tsx
+++ b/e2e/support/helpers/e2e-embedding-sdk-interactive-question-helpers.tsx
@@ -6,8 +6,14 @@ export function saveInteractiveQuestionAsNewQuestion(options: {
questionName: string;
entityName: string;
collectionPickerPath?: string[];
+ getModal?: () => Cypress.Chainable;
}) {
- const { questionName, entityName, collectionPickerPath } = options;
+ const {
+ questionName,
+ entityName,
+ collectionPickerPath,
+ getModal = modal,
+ } = options;
cy.intercept("POST", "/api/card").as("createCard");
@@ -16,7 +22,7 @@ export function saveInteractiveQuestionAsNewQuestion(options: {
popover().findByText(`See these ${entityName}`).click();
cy.findByRole("button", { name: "Save" }).click();
- modal().within(() => {
+ getModal().within(() => {
cy.findByText("Save as new question").click();
cy.findByPlaceholderText("What is the name of your question?")
@@ -30,7 +36,7 @@ export function saveInteractiveQuestionAsNewQuestion(options: {
pickEntity({ path: collectionPickerPath, select: true });
}
- modal().within(() => {
+ getModal().within(() => {
cy.findByRole("button", { name: "Save" }).click();
});
}
diff --git a/e2e/support/helpers/e2e-ui-elements-helpers.js b/e2e/support/helpers/e2e-ui-elements-helpers.js
index 29fead7ed84..e51241b53b0 100644
--- a/e2e/support/helpers/e2e-ui-elements-helpers.js
+++ b/e2e/support/helpers/e2e-ui-elements-helpers.js
@@ -31,9 +31,7 @@ export function menu() {
}
export function modal(options = {}) {
- const MODAL_SELECTOR = ".mb-mantine-Modal-content[role='dialog']";
- const LEGACY_MODAL_SELECTOR = "[data-testid=modal]";
- return cy.get([MODAL_SELECTOR, LEGACY_MODAL_SELECTOR].join(","), options);
+ return cy.get(".mb-mantine-Modal-content[role='dialog']", options);
}
export function tooltip() {
diff --git a/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx
index 6fdd1f1a4ba..51750e35245 100644
--- a/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx
@@ -339,6 +339,7 @@ describe("scenarios > embedding-sdk > interactive-question", () => {
saveInteractiveQuestionAsNewQuestion({
entityName: "Orders",
questionName: "Sample Orders 4",
+ getModal: () => cy.findByTestId("modal"),
});
cy.wait("@createCard").then(({ response }) => {
diff --git a/e2e/test-component/scenarios/embedding-sdk/styles-tests.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/styles-tests.cy.spec.tsx
index f690cb5d21e..3caccddbb43 100644
--- a/e2e/test-component/scenarios/embedding-sdk/styles-tests.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/styles-tests.cy.spec.tsx
@@ -1,5 +1,4 @@
import {
- CreateDashboardModal,
EditableDashboard,
InteractiveDashboard,
InteractiveQuestion,
@@ -371,22 +370,6 @@ describe("scenarios > embedding-sdk > styles", () => {
});
describe("modals, popovers and tooltips", () => {
- it("legacy WindowModal modals should render with our styles", () => {
- // this test renders a create dashboard modal that, at this time, is using the legacy WindowModal
- cy.mount(
- <MetabaseProvider authConfig={DEFAULT_SDK_AUTH_PROVIDER_CONFIG}>
- <CreateDashboardModal />
- </MetabaseProvider>,
- );
-
- H.modal()
- .findByText("New dashboard")
- .should("exist")
- .and("have.css", "font-family", "Lato, Arial, sans-serif");
-
- // TODO: good place for a visual regression test
- });
-
it("mantine modals should render with our styles", () => {
cy.mount(
<MetabaseProvider authConfig={DEFAULT_SDK_AUTH_PROVIDER_CONFIG}>
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/library/LibraryPage/components/RootSnippetsCollectionMenu.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/library/LibraryPage/components/RootSnippetsCollectionMenu.tsx
index c68894d69f6..af230e1ee15 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/library/LibraryPage/components/RootSnippetsCollectionMenu.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/library/LibraryPage/components/RootSnippetsCollectionMenu.tsx
@@ -58,12 +58,11 @@ export const RootSnippetsCollectionMenu = ({
{t`View archived snippets`}
</Menu.Item>
</Menu.Dropdown>
- {showPermissionsModal && (
- <SnippetCollectionPermissionsModal
- collectionId={collectionId}
- onClose={togglePermissionsModal}
- />
- )}
+ <SnippetCollectionPermissionsModal
+ opened={showPermissionsModal}
+ collectionId={collectionId}
+ onClose={togglePermissionsModal}
+ />
</Menu>
);
};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/library/components/CollectionPermissionsModal/CollectionPermissionsModal.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/library/components/CollectionPermissionsModal/CollectionPermissionsModal.tsx
index f29690062af..d7219641979 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/library/components/CollectionPermissionsModal/CollectionPermissionsModal.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/library/components/CollectionPermissionsModal/CollectionPermissionsModal.tsx
@@ -1,9 +1,10 @@
import CollectionPermissionsModalBase from "metabase/admin/permissions/components/CollectionPermissionsModal/CollectionPermissionsModal";
import { skipToken, useListCollectionsQuery } from "metabase/api";
-import { Modal } from "metabase/common/components/Modal";
import type { CollectionPermissionsModalProps } from "metabase/plugins";
+import { Modal } from "metabase/ui";
export function CollectionPermissionsModal({
+ opened,
collectionId,
namespace,
onClose,
@@ -13,7 +14,13 @@ export function CollectionPermissionsModal({
);
return (
- <Modal onClose={onClose}>
+ <Modal
+ opened={opened}
+ onClose={onClose}
+ size="lg"
+ withCloseButton={false}
+ padding={0}
+ >
<CollectionPermissionsModalBase
params={{ slug: String(collectionId) }}
namespace={namespace ?? null}
diff --git a/enterprise/frontend/src/metabase-enterprise/sandboxes/index.js b/enterprise/frontend/src/metabase-enterprise/sandboxes/index.js
index 31960ef0646..bd344a2e591 100644
--- a/enterprise/frontend/src/metabase-enterprise/sandboxes/index.js
+++ b/enterprise/frontend/src/metabase-enterprise/sandboxes/index.js
@@ -68,7 +68,6 @@ export function initializePlugin() {
key=":tableId/segmented"
path=":tableId/segmented"
modal={EditSandboxingModal}
- modalProps={{ enableMouseEvents: true }}
/>,
);
PLUGIN_ADMIN_PERMISSIONS_TABLE_GROUP_ROUTES.push(
@@ -76,7 +75,6 @@ export function initializePlugin() {
key="segmented/group/:groupId"
path="segmented/group/:groupId"
modal={EditSandboxingModal}
- modalProps={{ enableMouseEvents: true }}
/>,
);
PLUGIN_ADMIN_PERMISSIONS_TABLE_FIELDS_OPTIONS.push(OPTION_SEGMENTED);
diff --git a/enterprise/frontend/src/metabase-enterprise/snippets/components/SnippetCollectionPermissionsModal/SnippetCollectionPermissionsModal.tsx b/enterprise/frontend/src/metabase-enterprise/snippets/components/SnippetCollectionPermissionsModal/SnippetCollectionPermissionsModal.tsx
index c2efbdc7128..db13b3d5395 100644
--- a/enterprise/frontend/src/metabase-enterprise/snippets/components/SnippetCollectionPermissionsModal/SnippetCollectionPermissionsModal.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/snippets/components/SnippetCollectionPermissionsModal/SnippetCollectionPermissionsModal.tsx
@@ -1,16 +1,23 @@
import CollectionPermissionsModal from "metabase/admin/permissions/components/CollectionPermissionsModal/CollectionPermissionsModal";
import { useListCollectionsQuery } from "metabase/api";
-import { Modal } from "metabase/common/components/Modal";
import type { SnippetCollectionPermissionsModalProps } from "metabase/plugins";
+import { Modal } from "metabase/ui";
export function SnippetCollectionPermissionsModal({
+ opened,
collectionId,
onClose,
}: SnippetCollectionPermissionsModalProps) {
useListCollectionsQuery({ namespace: "snippets" });
return (
- <Modal onClose={onClose}>
+ <Modal
+ opened={opened}
+ onClose={onClose}
+ size="lg"
+ withCloseButton={false}
+ padding={0}
+ >
<CollectionPermissionsModal
params={{ slug: String(collectionId) }}
onClose={onClose}
diff --git a/frontend/src/embedding-sdk-bundle/components/public/ComponentProvider/ComponentProvider.tsx b/frontend/src/embedding-sdk-bundle/components/public/ComponentProvider/ComponentProvider.tsx
index dd7b97cebf6..6c9e3405787 100644
--- a/frontend/src/embedding-sdk-bundle/components/public/ComponentProvider/ComponentProvider.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/public/ComponentProvider/ComponentProvider.tsx
@@ -26,6 +26,7 @@ import { isEmbeddingEajs } from "metabase/embedding-sdk/config";
import { isEmbeddingThemeV1 } from "metabase/embedding-sdk/theme";
import { MetabaseReduxProvider, useSelector } from "metabase/redux";
import { setOptions } from "metabase/redux/embed";
+import { OverlayStackProvider } from "metabase/ui/components/overlays/overlay-stack";
import { EmotionCacheProvider } from "metabase/ui/components/theme/EmotionCacheProvider";
import { initializePlugins } from "sdk-ee-plugins";
@@ -141,42 +142,44 @@ export const ComponentProviderInternal = (
return (
<EmotionCacheProvider>
- <SdkThemeProvider theme={theme}>
- <EnsureSingleInstance
- groupId="component-providers"
- instanceId={ensureSingleInstanceId}
- >
- {({ isInstanceToRender }) => (
- <>
- <LocaleProvider locale={locale || instanceLocale}>
- {children}
-
- {isInstanceToRender && pluginsReady && (
- <ContentTranslationsProvider />
+ <OverlayStackProvider>
+ <SdkThemeProvider theme={theme}>
+ <EnsureSingleInstance
+ groupId="component-providers"
+ instanceId={ensureSingleInstanceId}
+ >
+ {({ isInstanceToRender }) => (
+ <>
+ <LocaleProvider locale={locale || instanceLocale}>
+ {children}
+
+ {isInstanceToRender && pluginsReady && (
+ <ContentTranslationsProvider />
+ )}
+ </LocaleProvider>
+
+ {isInstanceToRender && (
+ <>
+ <Global styles={SCOPED_CSS_RESET} />
+
+ <SdkFontsGlobalStyles
+ baseUrl={authConfig.metabaseInstanceUrl}
+ />
+
+ <SdkUsageProblemDisplay
+ authConfig={authConfig}
+ allowConsoleLog={allowConsoleLog}
+ isLocalHost={isLocalHost}
+ />
+
+ <PortalContainer />
+ </>
)}
- </LocaleProvider>
-
- {isInstanceToRender && (
- <>
- <Global styles={SCOPED_CSS_RESET} />
-
- <SdkFontsGlobalStyles
- baseUrl={authConfig.metabaseInstanceUrl}
- />
-
- <SdkUsageProblemDisplay
- authConfig={authConfig}
- allowConsoleLog={allowConsoleLog}
- isLocalHost={isLocalHost}
- />
-
- <PortalContainer />
- </>
- )}
- </>
- )}
- </EnsureSingleInstance>
- </SdkThemeProvider>
+ </>
+ )}
+ </EnsureSingleInstance>
+ </SdkThemeProvider>
+ </OverlayStackProvider>
</EmotionCacheProvider>
);
};
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/ActionCreator.tsx b/frontend/src/metabase/actions/containers/ActionCreator/ActionCreator.tsx
index 2da7237a35b..2af40b0e8ec 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/ActionCreator.tsx
+++ b/frontend/src/metabase/actions/containers/ActionCreator/ActionCreator.tsx
@@ -11,13 +11,13 @@ import {
useUpdateActionMutation,
} from "metabase/api";
import { LeaveRouteConfirmModal } from "metabase/common/components/LeaveConfirmModal";
-import { Modal } from "metabase/common/components/Modal";
import { useBeforeUnload } from "metabase/common/hooks/use-before-unload";
import { useCallbackEffect } from "metabase/common/hooks/use-callback-effect";
import { useToast } from "metabase/common/hooks/use-toast";
import { connect, useSelector } from "metabase/redux";
import type { State } from "metabase/redux/store";
import { getMetadata } from "metabase/selectors/metadata";
+import { Modal } from "metabase/ui";
import type Question from "metabase-lib/v1/Question";
import type Metadata from "metabase-lib/v1/metadata/Metadata";
import type {
@@ -171,19 +171,21 @@ function ActionCreator({ model, onSubmit, onClose, route }: Props) {
>
{renderEditorBody({ isEditable })}
</ActionCreatorView>
- {isSaveModalShown && (
- <Modal title={t`New Action`} onClose={handleCloseNewActionModal}>
- <CreateActionForm
- initialValues={{
- name: action.name,
- description: action.description,
- model_id: model?.id(),
- }}
- onCreate={handleCreate}
- onCancel={handleCloseNewActionModal}
- />
- </Modal>
- )}
+ <Modal
+ opened={isSaveModalShown}
+ title={t`New Action`}
+ onClose={handleCloseNewActionModal}
+ >
+ <CreateActionForm
+ initialValues={{
+ name: action.name,
+ description: action.description,
+ model_id: model?.id(),
+ }}
+ onCreate={handleCreate}
+ onCancel={handleCloseNewActionModal}
+ />
+ </Modal>
{route && (
<LeaveRouteConfirmModal
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/CreateActionForm/CreateActionForm.tsx b/frontend/src/metabase/actions/containers/ActionCreator/CreateActionForm/CreateActionForm.tsx
index 837abbf1667..c25ecd43cb3 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/CreateActionForm/CreateActionForm.tsx
+++ b/frontend/src/metabase/actions/containers/ActionCreator/CreateActionForm/CreateActionForm.tsx
@@ -60,7 +60,7 @@ function CreateActionForm({
name="name"
title={t`Name`}
placeholder={t`My new fantastic action`}
- autoFocus
+ data-autofocus
/>
<FormTextArea
name="description"
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/FormCreator/FieldSettingsPopover.tsx b/frontend/src/metabase/actions/containers/ActionCreator/FormCreator/FieldSettingsPopover.tsx
index 03420e70ada..70ec2787cf3 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/FormCreator/FieldSettingsPopover.tsx
+++ b/frontend/src/metabase/actions/containers/ActionCreator/FormCreator/FieldSettingsPopover.tsx
@@ -52,11 +52,7 @@ export function FieldSettingsPopover({
/>
</UnstyledButton>
</Popover.Target>
- <Popover.Dropdown
- // TODO: remove when the legacy Modal / RENDERED_POPOVERS stack is no longer used (GDGT-2575)
- setupSequencedCloseHandler={close}
- maw={400}
- >
+ <Popover.Dropdown maw={400}>
<FormCreatorPopoverBody
fieldSettings={fieldSettings}
onChange={onChange}
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/FormCreator/OptionEditor.tsx b/frontend/src/metabase/actions/containers/ActionCreator/FormCreator/OptionEditor.tsx
index f0a61a50f04..94e27dc23fd 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/FormCreator/OptionEditor.tsx
+++ b/frontend/src/metabase/actions/containers/ActionCreator/FormCreator/OptionEditor.tsx
@@ -111,11 +111,7 @@ export const OptionPopover = ({
<Icon name="list" size={20} tooltip={t`Change options`} />
</UnstyledButton>
</Popover.Target>
- <Popover.Dropdown
- // TODO: remove when the legacy Modal / RENDERED_POPOVERS stack is no longer used (GDGT-2575)
- setupSequencedCloseHandler={close}
- maw={400}
- >
+ <Popover.Dropdown maw={400}>
<OptionEditorContainer>
<TextArea
value={text}
diff --git a/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputForm.unit.spec.tsx b/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputForm.unit.spec.tsx
index dd7de6f1a5c..a0ffb124ea7 100644
--- a/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputForm.unit.spec.tsx
+++ b/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputForm.unit.spec.tsx
@@ -59,6 +59,7 @@ function setup(options?: Partial<ActionParametersInputModalProps>) {
async function setupModal(options?: Partial<ActionParametersInputModalProps>) {
render(
<ActionParametersInputModal
+ opened
showEmptyState={false}
title="Test Modal"
onClose={_.noop}
diff --git a/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputModal.tsx b/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputModal.tsx
index c67a9a87f4f..10820a2d9e1 100644
--- a/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputModal.tsx
+++ b/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputModal.tsx
@@ -1,16 +1,17 @@
import { t } from "ttag";
import { EmptyState } from "metabase/common/components/EmptyState";
-import { Modal } from "metabase/common/components/Modal";
import {
ModalContent,
ModalContentActionIcon,
} from "metabase/common/components/ModalContent";
+import { Modal } from "metabase/ui";
import type { ActionParametersInputFormProps } from "./ActionParametersInputForm";
import ActionParametersInputForm from "./ActionParametersInputForm";
interface ModalProps {
+ opened: boolean;
title: string;
showConfirmMessage?: boolean;
showEmptyState: boolean;
@@ -23,6 +24,7 @@ export type ActionParametersInputModalProps = ModalProps &
ActionParametersInputFormProps;
function ActionParametersInputModal({
+ opened,
showConfirmMessage,
showEmptyState,
title,
@@ -32,7 +34,14 @@ function ActionParametersInputModal({
...formProps
}: ActionParametersInputModalProps) {
return (
- <Modal data-testid="action-parameters-input-modal" onClose={onClose}>
+ <Modal
+ data-testid="action-parameters-input-modal"
+ opened={opened}
+ onClose={onClose}
+ size="lg"
+ withCloseButton={false}
+ padding={0}
+ >
<ModalContent
title={title}
headerActions={
diff --git a/frontend/src/metabase/actions/containers/ActionPicker/ActionPicker.tsx b/frontend/src/metabase/actions/containers/ActionPicker/ActionPicker.tsx
index 838d1094bb2..9a51ec14201 100644
--- a/frontend/src/metabase/actions/containers/ActionPicker/ActionPicker.tsx
+++ b/frontend/src/metabase/actions/containers/ActionPicker/ActionPicker.tsx
@@ -5,10 +5,15 @@ import { t } from "ttag";
import ActionCreator from "metabase/actions/containers/ActionCreator";
import { useListActionsQuery, useSearchQuery } from "metabase/api";
import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import { Modal } from "metabase/common/components/Modal";
import { useToggle } from "metabase/common/hooks/use-toggle";
import CS from "metabase/css/core/index.css";
-import { ActionIcon, Button, Icon } from "metabase/ui";
+import {
+ ActionIcon,
+ Button,
+ Icon,
+ Modal,
+ PREVENT_AUTOCOMPLETE_CLIPPING_MODAL_PROPS,
+} from "metabase/ui";
import type { Card, WritebackAction } from "metabase-types/api";
import {
@@ -144,17 +149,22 @@ function ModelActionPicker({
</EmptyModelStateContainer>
)}
</ModelCollapseSection>
- {isActionCreatorOpen && (
- <Modal wide onClose={closeModal}>
- <ActionCreator
- modelId={model.id}
- databaseId={model.database_id}
- actionId={editingActionId}
- onClose={closeModal}
- onSubmit={handleModalSubmit}
- />
- </Modal>
- )}
+ <Modal
+ {...PREVENT_AUTOCOMPLETE_CLIPPING_MODAL_PROPS}
+ opened={isActionCreatorOpen}
+ onClose={closeModal}
+ size="95%"
+ withCloseButton={false}
+ padding={0}
+ >
+ <ActionCreator
+ modelId={model.id}
+ databaseId={model.database_id}
+ actionId={editingActionId}
+ onClose={closeModal}
+ onSubmit={handleModalSubmit}
+ />
+ </Modal>
</>
);
}
diff --git a/frontend/src/metabase/admin/routes.tsx b/frontend/src/metabase/admin/routes.tsx
index ef0c0258596..30d2091053c 100644
--- a/frontend/src/metabase/admin/routes.tsx
+++ b/frontend/src/metabase/admin/routes.tsx
@@ -347,18 +347,11 @@ export const getRoutes = (
<ModalRoute
path=":jobKey"
modal={JobTriggersModal}
- modalProps={{ wide: true }}
+ modalProps={{ size: "85%" }}
/>
</Route>
<Route path="logs" component={Logs}>
- <ModalRoute
- path="levels"
- modal={LogLevelsModal}
- modalProps={{
- // EventSandbox interferes with mouse text selection in CodeMirror editor
- disableEventSandbox: true,
- }}
- />
+ <ModalRoute path="levels" modal={LogLevelsModal} />
</Route>
{PLUGIN_DEPENDENCIES.isEnabled && (
<Route
diff --git a/frontend/src/metabase/admin/settings/components/widgets/CustomGeoJSONWidget.tsx b/frontend/src/metabase/admin/settings/components/widgets/CustomGeoJSONWidget.tsx
index 0103f115bd9..860c6f838f9 100644
--- a/frontend/src/metabase/admin/settings/components/widgets/CustomGeoJSONWidget.tsx
+++ b/frontend/src/metabase/admin/settings/components/widgets/CustomGeoJSONWidget.tsx
@@ -7,12 +7,11 @@ import { useLazyLoadGeoJSONQuery } from "metabase/api/geojson";
import { useAdminSetting } from "metabase/api/utils";
import { ConfirmModal } from "metabase/common/components/ConfirmModal";
import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import { Modal } from "metabase/common/components/Modal";
import { Option, Select } from "metabase/common/components/Select";
import AdminS from "metabase/css/admin.module.css";
import ButtonsS from "metabase/css/components/buttons.module.css";
import CS from "metabase/css/core/index.css";
-import { Button, Ellipsified, Image, Stack, Text } from "metabase/ui";
+import { Button, Ellipsified, Image, Modal, Stack, Text } from "metabase/ui";
import { uuid } from "metabase/utils/uuid";
import { LeafletChoropleth } from "metabase/visualizations/components/LeafletChoropleth";
import type {
@@ -148,7 +147,13 @@ export const CustomGeoJSONWidget = () => {
)}
{map ? (
- <Modal wide>
+ <Modal
+ opened
+ onClose={handleCancel}
+ size="95%"
+ withCloseButton={false}
+ padding={0}
+ >
<div className={CS.p4}>
<EditMap
map={map}
diff --git a/frontend/src/metabase/admin/tools/components/LogLevelsModal/LogLevelsModal.unit.spec.tsx b/frontend/src/metabase/admin/tools/components/LogLevelsModal/LogLevelsModal.unit.spec.tsx
index 7cdedc89308..4a39d84795e 100644
--- a/frontend/src/metabase/admin/tools/components/LogLevelsModal/LogLevelsModal.unit.spec.tsx
+++ b/frontend/src/metabase/admin/tools/components/LogLevelsModal/LogLevelsModal.unit.spec.tsx
@@ -59,7 +59,7 @@ const setup = ({ error, presets = [PRESET_A, PRESET_B] }: SetupOpts = {}) => {
<ModalRoute
path="levels"
modal={LogLevelsModal}
- modalProps={{ enableTransition: false }}
+ modalProps={{ transitionProps: { duration: 0 } }}
/>
</Route>,
{
diff --git a/frontend/src/metabase/app.js b/frontend/src/metabase/app.js
index 1dbab368f0b..0a6e21ee86e 100644
--- a/frontend/src/metabase/app.js
+++ b/frontend/src/metabase/app.js
@@ -54,6 +54,7 @@ import registerVisualizations from "metabase/visualizations/register";
import { HistoryProvider } from "./history";
import { RouterProvider } from "./router";
import { getStore } from "./store";
+import { OverlayStackProvider } from "./ui/components/overlays/overlay-stack";
// remove trailing slash
const BASENAME = window.MetabaseRoot.replace(/\/+$/, "");
@@ -97,15 +98,17 @@ function _init(reducers, getRoutes, callback) {
<MetabaseReduxProvider store={store}>
<EmotionCacheProvider>
<DragDropContextProvider backend={ModifiedBackend} context={{ window }}>
- <AppThemeProvider>
- <GlobalStyles />
- {createPortal(<PortalContainer />, document.body)}
- <MetabotProvider>
- <HistoryProvider history={syncedHistory}>
- <RouterProvider>{routes}</RouterProvider>
- </HistoryProvider>
- </MetabotProvider>
- </AppThemeProvider>
+ <OverlayStackProvider>
+ <AppThemeProvider>
+ <GlobalStyles />
+ {createPortal(<PortalContainer />, document.body)}
+ <MetabotProvider>
+ <HistoryProvider history={syncedHistory}>
+ <RouterProvider>{routes}</RouterProvider>
+ </HistoryProvider>
+ </MetabotProvider>
+ </AppThemeProvider>
+ </OverlayStackProvider>
</DragDropContextProvider>
</EmotionCacheProvider>
</MetabaseReduxProvider>,
diff --git a/frontend/src/metabase/collections/components/CollectionRowMenu/CollectionRowMenu.tsx b/frontend/src/metabase/collections/components/CollectionRowMenu/CollectionRowMenu.tsx
index cd1ed6e0f2c..b984b61d64c 100644
--- a/frontend/src/metabase/collections/components/CollectionRowMenu/CollectionRowMenu.tsx
+++ b/frontend/src/metabase/collections/components/CollectionRowMenu/CollectionRowMenu.tsx
@@ -199,14 +199,15 @@ export function CollectionRowMenu(props: CollectionRowMenuProps) {
onClose={toggleEditModal}
/>
)}
- {isPermissionsModalOpen && collection.namespace === "snippets" && (
+ {collection.namespace === "snippets" ? (
<PLUGIN_SNIPPET_FOLDERS.CollectionPermissionsModal
+ opened={isPermissionsModalOpen}
collectionId={collection.id}
onClose={togglePermissionsModal}
/>
- )}
- {isPermissionsModalOpen && collection.namespace !== "snippets" && (
+ ) : (
<PLUGIN_LIBRARY.CollectionPermissionsModal
+ opened={isPermissionsModalOpen}
collectionId={collection.id}
namespace={collection.namespace}
onClose={togglePermissionsModal}
diff --git a/frontend/src/metabase/collections/containers/CreateCollectionModal.tsx b/frontend/src/metabase/collections/containers/CreateCollectionModal.tsx
index ade3cd7d1e2..f8c9dd3dbf5 100644
--- a/frontend/src/metabase/collections/containers/CreateCollectionModal.tsx
+++ b/frontend/src/metabase/collections/containers/CreateCollectionModal.tsx
@@ -3,7 +3,6 @@ import { push } from "react-router-redux";
import { t } from "ttag";
import { useCreateCollectionMutation } from "metabase/api";
-import { useEscapeToCloseModal } from "metabase/common/hooks/use-escape-to-close-modal";
import { PLUGIN_LIBRARY } from "metabase/plugins";
import { useDispatch } from "metabase/redux";
import { Modal } from "metabase/ui";
@@ -64,8 +63,6 @@ function CreateCollectionModal({
[createCollection, dispatch, onCreate, onClose, shouldNavigateOnCreate],
);
- useEscapeToCloseModal(onClose);
-
return (
<Modal
opened
@@ -74,7 +71,6 @@ function CreateCollectionModal({
data-testid="new-collection-modal"
padding="40px"
title={t`New collection`}
- closeOnEscape={false}
>
<CreateCollectionForm
{...props}
diff --git a/frontend/src/metabase/common/CreateDashboard/CreateDashboardModal.tsx b/frontend/src/metabase/common/CreateDashboard/CreateDashboardModal.tsx
index ac4c131561a..b8e6971b9d4 100644
--- a/frontend/src/metabase/common/CreateDashboard/CreateDashboardModal.tsx
+++ b/frontend/src/metabase/common/CreateDashboard/CreateDashboardModal.tsx
@@ -3,7 +3,6 @@ import { push } from "react-router-redux";
import { t } from "ttag";
import type { SdkCollectionId } from "embedding-sdk-bundle/types";
-import { useEscapeToCloseModal } from "metabase/common/hooks/use-escape-to-close-modal";
import { useDispatch } from "metabase/redux";
import { Modal, type ModalProps } from "metabase/ui";
import * as Urls from "metabase/urls";
@@ -39,15 +38,12 @@ export const CreateDashboardModal = ({
[onCreate, onClose, dispatch],
);
- useEscapeToCloseModal(onClose);
-
return (
<Modal
title={t`New dashboard`}
onClose={() => onClose?.()}
data-testid="new-dashboard-modal"
size="lg"
- closeOnEscape={false}
opened={opened}
>
<CreateDashboardForm
diff --git a/frontend/src/metabase/common/components/AutocompleteInput/AutocompleteInput.tsx b/frontend/src/metabase/common/components/AutocompleteInput/AutocompleteInput.tsx
index 3f2af12cc5f..5be48dd6697 100644
--- a/frontend/src/metabase/common/components/AutocompleteInput/AutocompleteInput.tsx
+++ b/frontend/src/metabase/common/components/AutocompleteInput/AutocompleteInput.tsx
@@ -120,10 +120,7 @@ export const AutocompleteInput = ({
}}
/>
</Popover.Target>
- <Popover.Dropdown
- // TODO: remove when the legacy Modal / RENDERED_POPOVERS stack is no longer used (GDGT-2575)
- setupSequencedCloseHandler={close}
- >
+ <Popover.Dropdown>
<OptionsList ref={optionsListRef} onMouseDown={handleListMouseDown}>
{filteredOptions.map((item, index) => (
<SelectList.Item
diff --git a/frontend/src/metabase/common/components/ColorPicker/ColorPicker.tsx b/frontend/src/metabase/common/components/ColorPicker/ColorPicker.tsx
index 4a9e2308bf5..27e107a654f 100644
--- a/frontend/src/metabase/common/components/ColorPicker/ColorPicker.tsx
+++ b/frontend/src/metabase/common/components/ColorPicker/ColorPicker.tsx
@@ -26,7 +26,7 @@ export const ColorPicker = forwardRef(function ColorPicker(
const [opened, { open, close }] = useDisclosure(false);
return (
- <Popover opened={opened} onClose={close} position="bottom-start">
+ <Popover opened={opened} onDismiss={close} position="bottom-start">
<Popover.Target>
<ColorPickerTrigger
{...props}
@@ -38,10 +38,7 @@ export const ColorPicker = forwardRef(function ColorPicker(
onChange={onChange}
/>
</Popover.Target>
- <Popover.Dropdown
- // TODO: remove when the legacy Modal / RENDERED_POPOVERS stack is no longer used (GDGT-2575)
- setupSequencedCloseHandler={close}
- >
+ <Popover.Dropdown>
<ColorPickerContent value={value} onChange={onChange} />
</Popover.Dropdown>
</Popover>
diff --git a/frontend/src/metabase/common/components/ColorPicker/ColorPillPicker.tsx b/frontend/src/metabase/common/components/ColorPicker/ColorPillPicker.tsx
index 0c489fbb167..32225e842ef 100644
--- a/frontend/src/metabase/common/components/ColorPicker/ColorPillPicker.tsx
+++ b/frontend/src/metabase/common/components/ColorPicker/ColorPillPicker.tsx
@@ -47,17 +47,13 @@ export const ColorPillPicker = forwardRef(function ColorPillPicker(
const [isOpened, { open, close }] = useDisclosure(false);
return (
- <Popover opened={isOpened} onClose={close} position="bottom-start">
+ <Popover opened={isOpened} onDismiss={close} position="bottom-start">
<Popover.Target>
<Group {...props} ref={ref} wrap="nowrap">
<ColorPill color={color} onClick={open} />
</Group>
</Popover.Target>
- <Popover.Dropdown
- // TODO: remove when the legacy Modal / RENDERED_POPOVERS stack is no longer used (GDGT-2575)
- setupSequencedCloseHandler={close}
- className={S.ColorPillPicker}
- >
+ <Popover.Dropdown className={S.ColorPillPicker}>
<ColorPickerContent
value={color}
onChange={(nextColor) => {
diff --git a/frontend/src/metabase/common/components/CopyModal/CopyModal.tsx b/frontend/src/metabase/common/components/CopyModal/CopyModal.tsx
index 4c4426d2817..469a448f454 100644
--- a/frontend/src/metabase/common/components/CopyModal/CopyModal.tsx
+++ b/frontend/src/metabase/common/components/CopyModal/CopyModal.tsx
@@ -3,7 +3,6 @@ import { t } from "ttag";
import { useGetDefaultCollectionId } from "metabase/collections/hooks";
import { CopyDashboardFormConnected } from "metabase/common/components/CopyDashboardForm";
-import { useEscapeToCloseModal } from "metabase/common/hooks/use-escape-to-close-modal";
import { DocumentCopyForm } from "metabase/documents/components/DocumentCopyForm/DocumentCopyForm";
import { CopyCardForm } from "metabase/questions/components/CopyCardForm/CopyCardForm";
import { Modal } from "metabase/ui";
@@ -38,8 +37,6 @@ export function CopyModal(props: CopyModalProps) {
name: resolvedObjectWithDefaultCollection.name + " - " + t`Duplicate`,
};
- useEscapeToCloseModal(onClose);
-
return (
<Modal
title={
@@ -47,7 +44,6 @@ export function CopyModal(props: CopyModalProps) {
}
opened
onClose={onClose}
- closeOnEscape={false}
>
{entityType === "dashboards" && (
<CopyDashboardFormConnected
diff --git a/frontend/src/metabase/common/components/EntityItem/EntityItem.module.css b/frontend/src/metabase/common/components/EntityItem/EntityItem.module.css
index 1599c442488..b02113e9d19 100644
--- a/frontend/src/metabase/common/components/EntityItem/EntityItem.module.css
+++ b/frontend/src/metabase/common/components/EntityItem/EntityItem.module.css
@@ -1,27 +1,13 @@
-.menuItem.menuItem {
- color: var(--mb-color-text-primary);
+.menuItem {
font-weight: 700;
}
-.menuItem.menuItem:hover:not([data-disabled="true"]) {
- color: var(--mb-color-brand);
- background-color: var(--mb-color-background-secondary);
+.menuItem:hover:not([data-disabled="true"]) {
+ color: var(--mb-color-brand) !important;
+ background-color: var(--mb-color-background-secondary) !important;
}
-.menuItem.menuItem[data-disabled="true"] {
- color: var(--mb-color-text-tertiary);
- opacity: 1;
-}
-
-.menuItem.menuItem [data-position="left"] {
- color: inherit;
-}
-
-.dangerItem.dangerItem {
- color: var(--mb-color-danger);
-}
-
-.dangerItem.dangerItem:hover:not([data-disabled="true"]) {
- color: var(--mb-color-danger);
- background-color: var(--mb-color-background-error);
+.dangerItem:hover:not([data-disabled="true"]) {
+ color: var(--mb-color-danger) !important;
+ background-color: var(--mb-color-background-error) !important;
}
diff --git a/frontend/src/metabase/common/components/EntityItem/EntityItem.tsx b/frontend/src/metabase/common/components/EntityItem/EntityItem.tsx
index 1cb54f3cde7..771a7d5e637 100644
--- a/frontend/src/metabase/common/components/EntityItem/EntityItem.tsx
+++ b/frontend/src/metabase/common/components/EntityItem/EntityItem.tsx
@@ -35,6 +35,7 @@ import {
Menu,
Tooltip,
} from "metabase/ui";
+import type { ColorName } from "metabase/ui/colors/types";
import * as Urls from "metabase/urls";
import type { CollectionItem, IconName } from "metabase-types/api";
@@ -317,10 +318,14 @@ function EntityItemMenu({
const disabledProps = action.disabled
? { "aria-disabled": true, "data-disabled": true }
: {};
+ const dangerColor: ColorName | undefined = action.danger
+ ? "danger"
+ : undefined;
const menuItemProps = {
...disabledProps,
className: cx(S.menuItem, { [S.dangerItem]: action.danger }),
leftSection: getLeftSection(action.icon),
+ c: dangerColor,
};
if (action.link) {
diff --git a/frontend/src/metabase/common/components/MetadataInfo/Popover/Popover.tsx b/frontend/src/metabase/common/components/MetadataInfo/Popover/Popover.tsx
index ec9279860db..85d47084b31 100644
--- a/frontend/src/metabase/common/components/MetadataInfo/Popover/Popover.tsx
+++ b/frontend/src/metabase/common/components/MetadataInfo/Popover/Popover.tsx
@@ -4,9 +4,6 @@ import { useCallback, useState } from "react";
import Animation from "metabase/css/core/animation.module.css";
import type { HoverCardProps } from "metabase/ui";
import { HoverCard, useDelayGroup } from "metabase/ui";
-// TODO: drop the close-handler registration below when the legacy Modal /
-// RENDERED_POPOVERS stack is no longer used (GDGT-2575)
-import { useSequencedContentCloseHandler } from "metabase/ui/hooks/use-sequenced-content-close-handler";
// Initially, the user will have to hover for this long to open the popover
const POPOVER_SLOW_OPEN_DELAY = 250;
@@ -46,19 +43,15 @@ export function Popover({
const [isOpen, setIsOpen] = useState(false);
- const { setupCloseHandler, removeCloseHandler } =
- useSequencedContentCloseHandler();
-
const handleOpen = useCallback(() => {
group.onOpen();
setIsOpen(true);
}, [group]);
const handleClose = useCallback(() => {
- removeCloseHandler();
group.onClose();
setIsOpen(false);
- }, [removeCloseHandler, group]);
+ }, [group]);
return (
<HoverCard
@@ -81,14 +74,7 @@ export function Popover({
onMouseUp={stopPropagation}
className={group.shouldDelay ? Animation.fadeIn : undefined}
>
- <WidthBound
- width={width}
- ref={(node) => {
- setupCloseHandler(node, () => setIsOpen(false));
- }}
- >
- {isOpen && content}
- </WidthBound>
+ <WidthBound width={width}>{isOpen && content}</WidthBound>
</Dropdown>
</HoverCard>
);
diff --git a/frontend/src/metabase/common/components/Modal/MaybeOnClickOutsideWrapper.tsx b/frontend/src/metabase/common/components/Modal/MaybeOnClickOutsideWrapper.tsx
deleted file mode 100644
index f7a70463c71..00000000000
--- a/frontend/src/metabase/common/components/Modal/MaybeOnClickOutsideWrapper.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-import { OnClickOutsideWrapper } from "metabase/common/components/OnClickOutsideWrapper";
-
-export function MaybeOnClickOutsideWrapper({
- children,
- closeOnClickOutside = false,
- ...props
-}: {
- children: React.ReactNode;
- closeOnClickOutside?: boolean;
-} & React.ComponentProps<typeof OnClickOutsideWrapper>) {
- // TODO: should be !closeOnClickOutside, however it breaks modal states in some places
- // (e.g. ESC button closes 2 stacked modals instead of just the top one)
- return closeOnClickOutside ? (
- <>{children}</>
- ) : (
- <OnClickOutsideWrapper {...props}>{children}</OnClickOutsideWrapper>
- );
-}
diff --git a/frontend/src/metabase/common/components/Modal/Modal.tsx b/frontend/src/metabase/common/components/Modal/Modal.tsx
deleted file mode 100644
index 9f23d895aea..00000000000
--- a/frontend/src/metabase/common/components/Modal/Modal.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-import type { WindowModalProps } from "metabase/common/components/Modal/WindowModal";
-import { WindowModal } from "metabase/common/components/Modal/WindowModal";
-import { useDisableCommandPalette } from "metabase/ui/hooks/use-disable-command-palette";
-
-export type ModalProps = WindowModalProps;
-
-/** @deprecated use Modal from metabase/ui */
-export const Modal = ({ isOpen = true, ...props }: ModalProps) => {
- useDisableCommandPalette({ disabled: isOpen });
- return <WindowModal isOpen={isOpen} {...props} />;
-};
diff --git a/frontend/src/metabase/common/components/Modal/WindowModal.tsx b/frontend/src/metabase/common/components/Modal/WindowModal.tsx
deleted file mode 100644
index 6fced32a87a..00000000000
--- a/frontend/src/metabase/common/components/Modal/WindowModal.tsx
+++ /dev/null
@@ -1,194 +0,0 @@
-import cx from "classnames";
-import type { CSSProperties } from "react";
-import { Component } from "react";
-import { CSSTransition, TransitionGroup } from "react-transition-group";
-
-import { MaybeOnClickOutsideWrapper } from "metabase/common/components/Modal/MaybeOnClickOutsideWrapper";
-import type {
- BaseModalProps,
- ModalSize,
-} from "metabase/common/components/Modal/utils";
-import {
- getModalContent,
- modalSizes,
-} from "metabase/common/components/Modal/utils";
-import { SandboxedPortal } from "metabase/common/components/SandboxedPortal";
-import { getPortalRootElement } from "metabase/common/utils/portal";
-import ModalS from "metabase/css/components/modal.module.css";
-import CS from "metabase/css/core/index.css";
-import ZIndex from "metabase/css/core/z-index.module.css";
-import { FocusTrap } from "metabase/ui";
-
-export type WindowModalProps = BaseModalProps & {
- isOpen?: boolean;
- onClose?: () => void;
- fullPageModal?: boolean;
- formModal?: boolean;
- style?: CSSProperties;
- "data-testid"?: string;
- "aria-labelledby"?: string;
- zIndex?: number;
- disableEventSandbox?: boolean;
- trapFocus?: boolean;
-} & {
- [size in ModalSize]?: boolean;
-};
-
-const MODAL_CLASSES = {
- small: ModalS.ModalSmall,
- medium: ModalS.ModalMedium,
- wide: ModalS.ModalWide,
- tall: ModalS.ModalTall,
- fit: ModalS.ModalFit,
-} as const;
-
-export class WindowModal extends Component<WindowModalProps> {
- _modalElement: HTMLDivElement;
-
- static defaultProps = {
- className: ModalS.Modal,
- enableTransition: true,
- trapFocus: true,
- };
-
- constructor(props: WindowModalProps) {
- super(props);
-
- this._modalElement = document.createElement("div");
- this._modalElement.className = ModalS.ModalContainer;
-
- if (props.zIndex != null) {
- this._modalElement.style.zIndex = String(props.zIndex);
- }
-
- if (props.isOpen) {
- getPortalRootElement().appendChild(this._modalElement);
- }
- }
-
- componentDidUpdate(prevProps: WindowModalProps) {
- if (!prevProps.isOpen && this.props.isOpen) {
- getPortalRootElement().appendChild(this._modalElement);
- }
- }
-
- componentWillUnmount() {
- if (this._modalElement.parentNode) {
- this._modalElement.parentNode.removeChild(this._modalElement);
- }
- }
-
- handleDismissal = () => {
- if (this.props.onClose) {
- this.props.onClose();
- }
- };
-
- _modalComponent() {
- const className = cx(
- this.props.className,
- ...modalSizes
- .filter((type) => this.props[type])
- .map((type) => MODAL_CLASSES[type]),
- );
- return (
- <MaybeOnClickOutsideWrapper
- backdropElement={this._modalElement}
- handleDismissal={this.handleDismissal}
- closeOnClickOutside={this.props.closeOnClickOutside}
- >
- <FocusTrap active={this.props.trapFocus}>
- <div
- className={cx(
- className,
- CS.relative,
- CS.bgWhite,
- CS.rounded,
- CS.textDark,
- ZIndex.Overlay,
- )}
- role="dialog"
- data-testid="modal"
- aria-labelledby={this.props["aria-labelledby"]}
- >
- {getModalContent({
- ...this.props,
- fullPageModal: false,
- // if there is a form then its a form modal, or if there's a form
- // modal prop use that
- formModal: !!this.props.form || this.props.formModal,
- })}
- </div>
- </FocusTrap>
- </MaybeOnClickOutsideWrapper>
- );
- }
-
- render() {
- const {
- disableEventSandbox,
- enableMouseEvents,
- isOpen,
- style,
- enableTransition,
- "data-testid": dataTestId,
- } = this.props;
- const backdropClassnames = cx(
- CS.flex,
- CS.justifyCenter,
- CS.alignCenter,
- CS.fixed,
- CS.top,
- CS.left,
- CS.bottom,
- CS.right,
- );
-
- return (
- <SandboxedPortal
- container={this._modalElement}
- disabled={disableEventSandbox}
- enableMouseEvents={enableMouseEvents}
- // disable keydown to allow FocusTrap to work
- unsandboxedEvents={["onKeyDown"]}
- >
- <TransitionGroup
- appear={enableTransition}
- enter={enableTransition}
- exit={enableTransition}
- >
- {isOpen && (
- <CSSTransition
- key="modal"
- classNames={{
- appear: ModalS.ModalAppear,
- appearActive: ModalS.ModalAppearActive,
- enter: ModalS.ModalEnter,
- enterActive: ModalS.ModalEnterActive,
- exit: ModalS.ModalExit,
- exitActive: ModalS.ModalExitActive,
- }}
- timeout={{
- appear: 250,
- enter: 250,
- exit: 250,
- }}
- >
- <div
- className={cx(
- ModalS.ModalBackdrop,
- backdropClassnames,
- ZIndex.Overlay,
- )}
- style={style}
- data-testid={dataTestId}
- >
- {this._modalComponent()}
- </div>
- </CSSTransition>
- )}
- </TransitionGroup>
- </SandboxedPortal>
- );
- }
-}
diff --git a/frontend/src/metabase/common/components/Modal/WindowModal.unit.spec.tsx b/frontend/src/metabase/common/components/Modal/WindowModal.unit.spec.tsx
deleted file mode 100644
index 13f2e9728ea..00000000000
--- a/frontend/src/metabase/common/components/Modal/WindowModal.unit.spec.tsx
+++ /dev/null
@@ -1,61 +0,0 @@
-import userEvent from "@testing-library/user-event";
-import { useState } from "react";
-
-import { render, screen, waitFor } from "__support__/ui";
-import { WindowModal } from "metabase/common/components/Modal/WindowModal";
-
-const WINDOW_MODAL_CONTENT = "Close modal";
-
-const TestWindowModalComponent = () => {
- const [isOpen, setIsOpen] = useState(false);
-
- return (
- <div>
- <button data-testid="modal-toggle" onClick={() => setIsOpen(!isOpen)}>
- Toggle modal
- </button>
- <WindowModal isOpen={isOpen}>
- <button data-testid="modal-button" onClick={() => setIsOpen(!isOpen)}>
- {WINDOW_MODAL_CONTENT}
- </button>
- </WindowModal>
- </div>
- );
-};
-
-const setup = () => {
- render(<TestWindowModalComponent />);
-};
-
-describe("WindowModal", () => {
- it("should render modal content when the modal is opened", async () => {
- setup();
- await userEvent.click(screen.getByTestId("modal-toggle"));
- expect(screen.getByText(WINDOW_MODAL_CONTENT)).toBeInTheDocument();
- });
-
- it("should not render modal content if the modal has been closed", async () => {
- setup();
- await userEvent.click(screen.getByTestId("modal-toggle"));
- expect(screen.getByText(WINDOW_MODAL_CONTENT)).toBeInTheDocument();
- await userEvent.click(screen.getByTestId("modal-toggle"));
-
- await waitFor(() =>
- expect(screen.queryByText(WINDOW_MODAL_CONTENT)).not.toBeInTheDocument(),
- );
- });
-
- it("should only allow keyboard navigation on elements inside the modal", async () => {
- setup();
- await userEvent.click(screen.getByTestId("modal-toggle"));
- await screen.findByText(WINDOW_MODAL_CONTENT);
-
- // first tab to establish that the focus is on the modal button
- await userEvent.tab();
- expect(screen.getByTestId("modal-button")).toHaveFocus();
-
- // second tab to make sure that focus doesn't leave the modal or the button.
- await userEvent.tab();
- expect(screen.getByTestId("modal-button")).toHaveFocus();
- });
-});
diff --git a/frontend/src/metabase/common/components/Modal/index.tsx b/frontend/src/metabase/common/components/Modal/index.tsx
deleted file mode 100644
index 0e1233d2ccd..00000000000
--- a/frontend/src/metabase/common/components/Modal/index.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { Modal } from "./Modal";
diff --git a/frontend/src/metabase/common/components/Modal/utils.tsx b/frontend/src/metabase/common/components/Modal/utils.tsx
deleted file mode 100644
index acc4298bb12..00000000000
--- a/frontend/src/metabase/common/components/Modal/utils.tsx
+++ /dev/null
@@ -1,32 +0,0 @@
-import * as React from "react";
-import _ from "underscore";
-
-import { ModalContent } from "metabase/common/components/ModalContent";
-
-export const modalSizes = ["small", "medium", "wide", "tall", "fit"] as const;
-export type ModalSize = (typeof modalSizes)[number];
-
-export type BaseModalProps = {
- children?: React.ReactNode;
- className?: string;
- enableMouseEvents?: boolean;
- enableTransition?: boolean;
- closeOnClickOutside?: boolean;
- noBackdrop?: boolean;
- noCloseOnBackdrop?: boolean;
- form?: unknown;
- title?: string | JSX.Element;
- footer?: string;
-};
-
-export function getModalContent(props: any) {
- if (
- React.Children.count(props.children) > 1 ||
- props.title != null ||
- props.footer != null
- ) {
- return <ModalContent {..._.omit(props, "className", "style")} />;
- } else {
- return React.Children.only(props.children);
- }
-}
diff --git a/frontend/src/metabase/common/components/OnClickOutsideWrapper/OnClickOutsideWrapper.tsx b/frontend/src/metabase/common/components/OnClickOutsideWrapper/OnClickOutsideWrapper.tsx
deleted file mode 100644
index 524fd11c0c3..00000000000
--- a/frontend/src/metabase/common/components/OnClickOutsideWrapper/OnClickOutsideWrapper.tsx
+++ /dev/null
@@ -1,91 +0,0 @@
-// TODO: delete together with the legacy Modal when it is migrated to Modal
-// from metabase/ui (GDGT-2575, this is the legacy Modal's registration in the
-// RENDERED_POPOVERS stack)
-import type { ReactNode } from "react";
-import { Children, Component, createRef } from "react";
-
-import { Box } from "metabase/ui";
-import {
- RENDERED_POPOVERS,
- removePopoverData,
- shouldClosePopover,
-} from "metabase/ui/hooks/use-sequenced-content-close-handler";
-
-interface OnClickOutsideWrapperProps {
- children: ReactNode;
- backdropElement?: Element;
- handleDismissal: () => void;
- ignoreElement?: Element;
-}
-
-interface PopoverData {
- contentEl: Element;
- backdropEl?: Element;
- close: (e: MouseEvent | KeyboardEvent) => void;
- ignoreEl?: Element;
-}
-
-export class OnClickOutsideWrapper extends Component<OnClickOutsideWrapperProps> {
- contentRef = createRef<HTMLDivElement>();
- _timeout: ReturnType<typeof setTimeout> | null = null;
- popoverData: PopoverData | null = null;
-
- componentDidMount() {
- // necessary to ignore click events that fire immediately, causing modals/popovers to close prematurely
- this._timeout = setTimeout(() => {
- const contentEl = this.contentRef.current;
- if (!contentEl) {
- return;
- }
-
- this.popoverData = {
- contentEl,
- backdropEl: this.props.backdropElement,
- close: () => this.props.handleDismissal(),
- ignoreEl: this.props.ignoreElement,
- };
-
- RENDERED_POPOVERS.push(this.popoverData);
-
- // HACK: set the z-index of the parent element to ensure it's always on top
- // NOTE: this actually doesn't seem to be working correctly for popovers since PopoverBody creates a stacking context
- (contentEl.parentNode as HTMLElement).style.zIndex = String(
- RENDERED_POPOVERS.length + 2,
- ); // HACK: add 2 to ensure it's in front of main and nav elements
-
- document.addEventListener("keydown", this._handleEvent, false);
- window.addEventListener("mousedown", this._handleEvent, true);
- }, 0);
- }
-
- componentWillUnmount() {
- document.removeEventListener("keydown", this._handleEvent, false);
- window.removeEventListener("mousedown", this._handleEvent, true);
- if (this._timeout) {
- clearTimeout(this._timeout);
- }
-
- // remove from the stack after a delay, if it is removed through some other
- // means this will happen too early causing parent modal to close
- const popoverData = this.popoverData;
- setTimeout(() => {
- if (popoverData) {
- removePopoverData(popoverData);
- }
- }, 0);
- }
-
- _handleEvent = (e: KeyboardEvent | MouseEvent) => {
- if (this.popoverData && shouldClosePopover(e, this.popoverData)) {
- this.popoverData.close(e);
- }
- };
-
- render() {
- return (
- <Box ref={this.contentRef} display="contents">
- {Children.only(this.props.children)}
- </Box>
- );
- }
-}
diff --git a/frontend/src/metabase/common/components/OnClickOutsideWrapper/index.tsx b/frontend/src/metabase/common/components/OnClickOutsideWrapper/index.tsx
deleted file mode 100644
index 02da583cc58..00000000000
--- a/frontend/src/metabase/common/components/OnClickOutsideWrapper/index.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { OnClickOutsideWrapper } from "./OnClickOutsideWrapper";
diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/NewCollectionDialog/NewCollectionDialog.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/NewCollectionDialog/NewCollectionDialog.tsx
index 57ab4de9fdc..630f9f91113 100644
--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/NewCollectionDialog/NewCollectionDialog.tsx
+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/NewCollectionDialog/NewCollectionDialog.tsx
@@ -5,7 +5,6 @@ import * as Yup from "yup";
import { useCreateCollectionMutation } from "metabase/api";
import { canPlaceEntityInCollection } from "metabase/collections/utils";
import { FormFooter } from "metabase/common/components/FormFooter";
-import { useEscapeToCloseModal } from "metabase/common/hooks/use-escape-to-close-modal";
import {
Form,
FormErrorMessage,
@@ -55,8 +54,6 @@ export const NewCollectionDialog = () => {
};
}, [path]);
- useEscapeToCloseModal(close, { capture: true });
-
if (!options.canCreateCollections) {
return null;
}
@@ -121,7 +118,6 @@ export const NewCollectionDialog = () => {
data-testid="create-collection-on-the-go"
trapFocus={true}
withCloseButton={false}
- closeOnEscape={false}
>
<FormProvider
initialValues={{ name: "" }}
diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/NewDashboardDialog/NewDashboardDialog.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/NewDashboardDialog/NewDashboardDialog.tsx
index 23ff79ba3f3..2c6de85abd6 100644
--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/NewDashboardDialog/NewDashboardDialog.tsx
+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/NewDashboardDialog/NewDashboardDialog.tsx
@@ -3,7 +3,6 @@ import { t } from "ttag";
import { useCreateDashboardMutation } from "metabase/api";
import { FormFooter } from "metabase/common/components/FormFooter";
-import { useEscapeToCloseModal } from "metabase/common/hooks/use-escape-to-close-modal";
import { canPlaceEntityInCollection } from "metabase/data-studio/utils";
import {
Form,
@@ -46,8 +45,6 @@ export const NewDashboardDialog = () => {
};
}, [path]);
- useEscapeToCloseModal(close, { capture: true });
-
if (!options.canCreateDashboards) {
return null;
}
@@ -101,7 +98,6 @@ export const NewDashboardDialog = () => {
data-testid="create-dashboard-on-the-go"
trapFocus={true}
withCloseButton={false}
- closeOnEscape={false}
styles={{
content: {
padding: "1rem",
diff --git a/frontend/src/metabase/common/components/SaveQuestionModal/SaveQuestionModal.tsx b/frontend/src/metabase/common/components/SaveQuestionModal/SaveQuestionModal.tsx
index e88722309e5..0b86a5bdb15 100644
--- a/frontend/src/metabase/common/components/SaveQuestionModal/SaveQuestionModal.tsx
+++ b/frontend/src/metabase/common/components/SaveQuestionModal/SaveQuestionModal.tsx
@@ -4,7 +4,6 @@ import {
} from "metabase/common/components/SaveQuestionForm";
import { SaveQuestionProvider } from "metabase/common/components/SaveQuestionForm/context";
import type { SaveQuestionProps } from "metabase/common/components/SaveQuestionForm/types";
-import { useEscapeToCloseModal } from "metabase/common/hooks/use-escape-to-close-modal";
import { Flex, Modal, type ModalProps } from "metabase/ui";
type SaveQuestionModalProps = Omit<SaveQuestionProps, "initialDashboardTabId"> &
@@ -22,8 +21,6 @@ export const SaveQuestionModal = ({
targetCollection,
...modalProps
}: SaveQuestionModalProps) => {
- useEscapeToCloseModal(onClose);
-
return (
<SaveQuestionProvider
question={question}
@@ -43,12 +40,7 @@ export const SaveQuestionModal = ({
initialCollectionId={initialCollectionId}
targetCollection={targetCollection}
>
- <Modal.Root
- padding="xl"
- {...modalProps}
- closeOnEscape={false}
- onClose={onClose}
- >
+ <Modal.Root padding="xl" {...modalProps} onClose={onClose}>
<Modal.Overlay />
<Modal.Content data-testid="save-question-modal">
<Modal.Header>
diff --git a/frontend/src/metabase/common/components/TabButton/TabButton.tsx b/frontend/src/metabase/common/components/TabButton/TabButton.tsx
index 449a7e1c0ba..63119da52a0 100644
--- a/frontend/src/metabase/common/components/TabButton/TabButton.tsx
+++ b/frontend/src/metabase/common/components/TabButton/TabButton.tsx
@@ -177,10 +177,7 @@ const _TabButton = forwardRef(function TabButton(
<Icon name="chevrondown" size={10} />
</ActionIcon>
</Popover.Target>
- <Popover.Dropdown
- // TODO: remove when the legacy Modal / RENDERED_POPOVERS stack is no longer used (GDGT-2575)
- setupSequencedCloseHandler={() => setIsMenuOpen(false)}
- >
+ <Popover.Dropdown>
<TabButtonMenu
menuItems={menuItems}
value={value}
diff --git a/frontend/src/metabase/common/hooks/use-escape-to-close-modal/index.ts b/frontend/src/metabase/common/hooks/use-escape-to-close-modal/index.ts
deleted file mode 100644
index 80a490be7a2..00000000000
--- a/frontend/src/metabase/common/hooks/use-escape-to-close-modal/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./use-escape-to-close-modal";
diff --git a/frontend/src/metabase/common/hooks/use-escape-to-close-modal/use-escape-to-close-modal.tsx b/frontend/src/metabase/common/hooks/use-escape-to-close-modal/use-escape-to-close-modal.tsx
deleted file mode 100644
index 5ad7946ba86..00000000000
--- a/frontend/src/metabase/common/hooks/use-escape-to-close-modal/use-escape-to-close-modal.tsx
+++ /dev/null
@@ -1,26 +0,0 @@
-import { useKey } from "react-use";
-
-type Handler = (event?: KeyboardEvent) => void;
-
-/*
- This hook is designed to be used in place of the `closeOnEscape` prop on some mantine modals.
- By default, the mantine modal prop will always capture the event, making it hard to override
- with other event handlers. This is especially tricky with the EntityPickerModal where it is
- generally the child of another modal (create collection / dashboard). By using this hook and
- applying the capture option where needed, we can control the order in which modals are
- dismissed when the user presses Escape.
-*/
-
-export const useEscapeToCloseModal = (
- handler: Handler,
- opts: AddEventListenerOptions = {},
-) => {
- useKey(
- "Escape",
- (e) => {
- e.stopPropagation();
- handler(e);
- },
- { options: opts },
- );
-};
diff --git a/frontend/src/metabase/css/components/modal.module.css b/frontend/src/metabase/css/components/modal.module.css
deleted file mode 100644
index c5e986e4332..00000000000
--- a/frontend/src/metabase/css/components/modal.module.css
+++ /dev/null
@@ -1,127 +0,0 @@
-.ModalContainer {
- position: absolute;
- z-index: var(--mb-overlay-z-index);
-}
-
-.Modal {
- margin: auto;
- width: 640px;
- box-shadow: 0 0 6px var(--mb-color-shadow);
- max-height: 90%;
- overflow-y: auto;
- border: 1px solid var(--mb-color-border);
-}
-
-/* On IE11, single flex item with `margin: auto` gets shifted to flex end
- * https://github.com/philipwalton/flexbugs/issues/157
- * Set margin to zero when using Flexbox in `WindowModal` component
- */
-.ModalBackdrop > .Modal {
- margin: 0;
-}
-
-.Modal.ModalSmall {
- width: 480px;
-} /* TODO - why is this one px? */
-.Modal.ModalMedium {
- width: 65%;
-}
-
-.Modal.ModalWide {
- width: 85%;
-}
-
-.Modal.ModalFit {
- width: auto;
- max-height: 100%;
-}
-
-.Modal.ModalTall {
- min-height: 85%;
-}
-
-.ModalFull {
- background-color: var(--mb-color-background-primary);
- position: fixed;
- top: 0;
- bottom: 0;
- left: 0;
- right: 0;
-}
-
-.ModalBackdrop {
- background-color: var(--mb-color-overlay);
-}
-
-/* TRANSITIONS */
-
-/* backdrop */
-
-.ModalBackdrop.ModalAppear,
-.ModalBackdrop.ModalEnter {
- background-color: color-mix(
- in srgb,
- var(--mb-color-background-primary-inverse) 1%,
- transparent
- );
-}
-
-.ModalBackdrop.ModalAppearActive,
-.ModalBackdrop.ModalEnterActive {
- transition: background-color 200ms ease-in-out;
- background-color: var(--mb-color-overlay);
-}
-
-.ModalBackdrop.ModalExit {
- background-color: var(--mb-color-overlay);
-}
-
-.ModalBackdrop.ModalExitActive {
- transition: background-color 200ms ease-in-out 100ms;
- background-color: color-mix(
- in srgb,
- var(--mb-color-background-primary-inverse) 1%,
- transparent
- );
-}
-
-/* modal */
-
-.ModalBackdrop.ModalAppear .Modal,
-.ModalBackdrop.ModalEnter .Modal {
- opacity: 0.01;
- transform: translate(0, 40px);
-}
-
-.ModalBackdrop.ModalAppearActive .Modal,
-.ModalBackdrop.ModalEnterActive .Modal {
- transition:
- opacity 200ms linear 100ms,
- transform 200ms ease-in-out 100ms;
- opacity: 1;
- transform: translate(0, 0);
-}
-
-.ModalBackdrop.ModalExit .Modal {
- opacity: 1;
- transform: translate(0, 0);
-}
-
-.ModalBackdrop.ModalExitActive .Modal {
- transition:
- opacity 200ms linear,
- transform 200ms ease-in-out;
- opacity: 0.01;
- transform: translate(0, -40px);
-}
-
-@media (prefers-reduced-motion) {
- .ModalBackdrop.ModalAppear,
- .ModalBackdrop.ModalEnter,
- .ModalBackdrop.ModalExit,
- .ModalBackdrop.ModalAppear .Modal,
- .ModalBackdrop.ModalEnter .Modal,
- .ModalBackdrop.ModalExit .Modal {
- transition: none;
- }
-}
diff --git a/frontend/src/metabase/css/index.module.css b/frontend/src/metabase/css/index.module.css
index 933c9112afe..564ab315e06 100644
--- a/frontend/src/metabase/css/index.module.css
+++ b/frontend/src/metabase/css/index.module.css
@@ -1,6 +1,5 @@
@import "./components/form.module.css";
@import "./components/list.module.css";
-@import "./components/modal.module.css";
@import "./components/tippy.module.css";
@import "./components/grabber.module.css";
@import "./admin.module.css";
diff --git a/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.tsx b/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.tsx
index 1c80630bccb..1543111cd1b 100644
--- a/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.tsx
+++ b/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.tsx
@@ -9,8 +9,8 @@ import { useActionInitialValues } from "metabase/actions/hooks/use-action-initia
import { getFormTitle, isImplicitUpdateAction } from "metabase/actions/utils";
import { actionApi, publicApi } from "metabase/api";
import { runRtkEndpoint } from "metabase/api/utils/run-rtk-endpoint";
-import { Modal } from "metabase/common/components/Modal";
import { useDispatch } from "metabase/redux";
+import { Modal, PREVENT_AUTOCOMPLETE_CLIPPING_MODAL_PROPS } from "metabase/ui";
import { getDashboardType } from "metabase/utils/dashboard";
import type {
ActionDashboardCard,
@@ -147,38 +147,39 @@ function ActionVizForm({
focus={isEditingDashcard}
onClick={onClick}
/>
- {showFormModal && (
- <ActionParametersInputModal
+ <ActionParametersInputModal
+ opened={showFormModal}
+ action={action}
+ mappedParameters={mappedParameters}
+ initialValues={initialValues}
+ title={title}
+ showEmptyState={shouldPrefetch && !hasPrefetchedValues}
+ showConfirmMessage={showConfirmMessage}
+ confirmMessage={action.visualization_settings?.confirmMessage}
+ onEdit={canEditAction ? handleActionEdit : undefined}
+ onSubmit={onModalSubmit}
+ onSubmitSuccess={handleSubmitSuccess}
+ onClose={() => setShowFormModal(false)}
+ onCancel={() => setShowFormModal(false)}
+ />
+ <Modal
+ {...PREVENT_AUTOCOMPLETE_CLIPPING_MODAL_PROPS}
+ opened={showEditModal}
+ data-testid="action-editor-modal"
+ onClose={closeEditModal}
+ size="95%"
+ withCloseButton={false}
+ padding={0}
+ >
+ <ActionCreator
action={action}
- mappedParameters={mappedParameters}
- initialValues={initialValues}
- title={title}
- showEmptyState={shouldPrefetch && !hasPrefetchedValues}
- showConfirmMessage={showConfirmMessage}
- confirmMessage={action.visualization_settings?.confirmMessage}
- onEdit={canEditAction ? handleActionEdit : undefined}
- onSubmit={onModalSubmit}
- onSubmitSuccess={handleSubmitSuccess}
- onClose={() => setShowFormModal(false)}
- onCancel={() => setShowFormModal(false)}
- />
- )}
- {showEditModal && (
- <Modal
- wide
- data-testid="action-editor-modal"
+ modelId={action.model_id}
+ databaseId={action.database_id}
+ actionId={action.id}
+ onSubmit={onActionEdit}
onClose={closeEditModal}
- >
- <ActionCreator
- action={action}
- modelId={action.model_id}
- databaseId={action.database_id}
- actionId={action.id}
- onSubmit={onActionEdit}
- onClose={closeEditModal}
- />
- </Modal>
- )}
+ />
+ </Modal>
</>
);
}
diff --git a/frontend/src/metabase/dashboard/components/DashCard/DashCardActionsPanel/ChartSettingsButton/ChartSettingsButton.tsx b/frontend/src/metabase/dashboard/components/DashCard/DashCardActionsPanel/ChartSettingsButton/ChartSettingsButton.tsx
index 9d6a579d2ef..4d65445e1e4 100644
--- a/frontend/src/metabase/dashboard/components/DashCard/DashCardActionsPanel/ChartSettingsButton/ChartSettingsButton.tsx
+++ b/frontend/src/metabase/dashboard/components/DashCard/DashCardActionsPanel/ChartSettingsButton/ChartSettingsButton.tsx
@@ -37,7 +37,7 @@ export function ChartSettingsButton({
<Modal
opened={isOpened}
onClose={close}
- size="85%"
+ size="95%"
padding={0}
withCloseButton={false}
styles={{
diff --git a/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.tsx b/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.tsx
index f140ea4907c..c2a07e15368 100644
--- a/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.tsx
+++ b/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.tsx
@@ -14,7 +14,6 @@ import {
import { runRtkEndpoint } from "metabase/api/utils/run-rtk-endpoint";
import { NotFound } from "metabase/common/components/ErrorPages";
import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import { Modal } from "metabase/common/components/Modal";
import {
DetailsGroup,
Header,
@@ -33,6 +32,7 @@ import {
Group,
Icon,
Menu,
+ Modal,
Stack,
Tooltip,
rem,
@@ -405,7 +405,13 @@ export function DetailViewSidesheet({
onSuccess={handleActionSuccess}
/>
- <Modal isOpen={isDeleteModalOpen} onClose={handleDeleteModalClose}>
+ <Modal
+ opened={isDeleteModalOpen}
+ onClose={handleDeleteModalClose}
+ size="lg"
+ withCloseButton={false}
+ padding={0}
+ >
<DeleteObjectModal
actionId={deleteActionId}
objectId={rowId}
diff --git a/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.unit.spec.tsx b/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.unit.spec.tsx
index 0ca1f0f05c2..d16066359cc 100644
--- a/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.unit.spec.tsx
+++ b/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.unit.spec.tsx
@@ -48,14 +48,13 @@ const table = createMockTable({
});
function setup({
- onNextClick = jest.fn(),
- onPreviousClick = jest.fn(),
showNav = true,
}: {
- onNextClick?: jest.Mock;
- onPreviousClick?: jest.Mock;
showNav?: boolean;
} = {}) {
+ const onNextClick = jest.fn();
+ const onPreviousClick = jest.fn();
+
setupDatabasesEndpoints([database]);
setupActionsEndpoints([updateAction]);
diff --git a/frontend/src/metabase/embedding/components/DashboardSharingEmbeddingModal/DashboardSharingEmbeddingModal.tsx b/frontend/src/metabase/embedding/components/DashboardSharingEmbeddingModal/DashboardSharingEmbeddingModal.tsx
index 4c737c0ca31..5a4cfd0ad97 100644
--- a/frontend/src/metabase/embedding/components/DashboardSharingEmbeddingModal/DashboardSharingEmbeddingModal.tsx
+++ b/frontend/src/metabase/embedding/components/DashboardSharingEmbeddingModal/DashboardSharingEmbeddingModal.tsx
@@ -30,7 +30,7 @@ export const DashboardSharingEmbeddingModal = ({
return (
<EmbedModal
- isOpen={isOpen}
+ opened={isOpen}
resource={dashboard}
resourceParameters={parameters}
resourceType="dashboard"
diff --git a/frontend/src/metabase/embedding/components/EmbedModal/EmbedModal.tsx b/frontend/src/metabase/embedding/components/EmbedModal/EmbedModal.tsx
index c331be32de9..8437d72136f 100644
--- a/frontend/src/metabase/embedding/components/EmbedModal/EmbedModal.tsx
+++ b/frontend/src/metabase/embedding/components/EmbedModal/EmbedModal.tsx
@@ -1,18 +1,18 @@
import { t } from "ttag";
-import { Modal } from "metabase/common/components/Modal";
import { StaticEmbedSetupPane } from "metabase/embedding/components/EmbedModal/StaticEmbedSetupPane";
import type {
EmbedResource,
EmbedResourceParameter,
GuestEmbedResourceType,
} from "metabase/embedding/types";
+import { Modal } from "metabase/ui";
import type { EmbeddingParameters } from "metabase-types/api";
import { EmbedModalHeader } from "./EmbedModal.styled";
interface EmbedModalProps {
- isOpen?: boolean;
+ opened: boolean;
resource: EmbedResource;
resourceType: GuestEmbedResourceType;
resourceParameters: EmbedResourceParameter[];
@@ -24,7 +24,7 @@ interface EmbedModalProps {
}
export const EmbedModal = ({
- isOpen,
+ opened,
resource,
resourceType,
resourceParameters,
@@ -34,12 +34,11 @@ export const EmbedModal = ({
onClose,
}: EmbedModalProps) => (
<Modal
- isOpen={isOpen}
+ opened={opened}
onClose={onClose}
- fit
- formModal={false}
- // needed to allow selecting with the mouse on the code samples
- enableMouseEvents
+ size="auto"
+ withCloseButton={false}
+ padding={0}
>
<EmbedModalHeader onClose={onClose} onBack={onBack}>
{t`Static embedding`}
diff --git a/frontend/src/metabase/embedding/components/QuestionEmbedWidget/QuestionEmbedWidget.tsx b/frontend/src/metabase/embedding/components/QuestionEmbedWidget/QuestionEmbedWidget.tsx
index 2b926d1b22a..792078db330 100644
--- a/frontend/src/metabase/embedding/components/QuestionEmbedWidget/QuestionEmbedWidget.tsx
+++ b/frontend/src/metabase/embedding/components/QuestionEmbedWidget/QuestionEmbedWidget.tsx
@@ -24,6 +24,7 @@ export const QuestionEmbedWidget = (props: QuestionEmbedWidgetProps) => {
return (
<EmbedModal
+ opened={true}
resource={card}
resourceType="question"
resourceParameters={getCardUiParameters(card, metadata)}
diff --git a/frontend/src/metabase/hoc/ModalRoute.tsx b/frontend/src/metabase/hoc/ModalRoute.tsx
index a848c5a485a..d93bc8e767e 100644
--- a/frontend/src/metabase/hoc/ModalRoute.tsx
+++ b/frontend/src/metabase/hoc/ModalRoute.tsx
@@ -3,8 +3,8 @@ import { Component, cloneElement } from "react";
import { Route } from "react-router";
import { push } from "react-router-redux";
-import { Modal } from "metabase/common/components/Modal";
import { connect } from "metabase/redux";
+import { Modal, type ModalProps } from "metabase/ui";
import MetabaseSettings from "metabase/utils/settings";
type RouteParams = Record<string, string | undefined>;
@@ -56,7 +56,7 @@ interface WrappedModalRouteProps {
const ModalWithRoute = (
ComposedModal: React.ComponentType<ComposedModalProps>,
- modalProps = {},
+ modalProps: Partial<ModalProps> = {},
noWrap = false,
) => {
class ModalRouteComponent extends Component<WrappedModalRouteProps> {
@@ -77,7 +77,14 @@ const ModalWithRoute = (
}
return (
- <Modal {...modalProps} onClose={this.onClose}>
+ <Modal
+ opened
+ onClose={this.onClose}
+ withCloseButton={false}
+ padding={0}
+ size="lg"
+ {...modalProps}
+ >
<ComposedModal {...this.props} onClose={this.onClose} />
</Modal>
);
@@ -99,7 +106,7 @@ export type ModalComponentProps = {
interface ModalRouteProps {
path: string;
modal: React.ComponentType<ModalComponentProps>;
- modalProps?: unknown;
+ modalProps?: Partial<ModalProps>;
noWrap?: boolean;
}
diff --git a/frontend/src/metabase/models/containers/ModelActions/ModelActions.unit.spec.tsx b/frontend/src/metabase/models/containers/ModelActions/ModelActions.unit.spec.tsx
index cf312d1986b..81598d454d0 100644
--- a/frontend/src/metabase/models/containers/ModelActions/ModelActions.unit.spec.tsx
+++ b/frontend/src/metabase/models/containers/ModelActions/ModelActions.unit.spec.tsx
@@ -227,12 +227,12 @@ async function setup({
<ModalRoute
path="new"
modal={ActionCreator}
- modalProps={{ enableTransition: false }}
+ modalProps={{ transitionProps: { duration: 0 } }}
/>
<ModalRoute
path=":actionId"
modal={ActionCreator}
- modalProps={{ enableTransition: false }}
+ modalProps={{ transitionProps: { duration: 0 } }}
/>
</Route>
</Route>
diff --git a/frontend/src/metabase/models/routes.tsx b/frontend/src/metabase/models/routes.tsx
index e482a8f302f..b4a5a47fb6e 100644
--- a/frontend/src/metabase/models/routes.tsx
+++ b/frontend/src/metabase/models/routes.tsx
@@ -4,33 +4,35 @@ import ActionCreatorModal from "metabase/actions/containers/ActionCreatorModal/A
import { ModelDetailPage } from "metabase/detail-view/pages/ModelDetailPage/ModelDetailPage";
import { ModalRoute } from "metabase/hoc/ModalRoute";
import ModelActions from "metabase/models/containers/ModelActions/ModelActions";
+import {
+ type ModalProps,
+ PREVENT_AUTOCOMPLETE_CLIPPING_MODAL_PROPS,
+} from "metabase/ui";
-export const getRoutes = () => (
- <Route path="/model/:slug/detail">
- <Route path="actions" component={ModelActions}>
- <ModalRoute
- path="new"
- modal={ActionCreatorModal}
- modalProps={{
- wide: true,
- enableTransition: false,
- closeOnClickOutside: false, // logic in component is reversed, so false is true.
- }}
- />
- <ModalRoute
- path=":actionId"
- modal={ActionCreatorModal}
- modalProps={{
- wide: true,
- enableTransition: false,
- closeOnClickOutside: false, // logic in component is reversed, so false is true.
- }}
- />
+export const getRoutes = () => {
+ const modalProps: Partial<ModalProps> = {
+ ...PREVENT_AUTOCOMPLETE_CLIPPING_MODAL_PROPS,
+ size: "95%",
+ };
+ return (
+ <Route path="/model/:slug/detail">
+ <Route path="actions" component={ModelActions}>
+ <ModalRoute
+ path="new"
+ modal={ActionCreatorModal}
+ modalProps={modalProps}
+ />
+ <ModalRoute
+ path=":actionId"
+ modal={ActionCreatorModal}
+ modalProps={modalProps}
+ />
+ </Route>
+ <Route path=":rowId" component={ModelDetailPage} />
+ <IndexRedirect to="actions" />
+ <Redirect from="usage" to="actions" />
+ <Redirect from="schema" to="actions" />
+ <Redirect from="*" to="actions" />
</Route>
- <Route path=":rowId" component={ModelDetailPage} />
- <IndexRedirect to="actions" />
- <Redirect from="usage" to="actions" />
- <Redirect from="schema" to="actions" />
- <Redirect from="*" to="actions" />
- </Route>
-);
+ );
+};
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/MainNavbarContainer.tsx b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/MainNavbarContainer.tsx
index 97e08b405be..ada221dab25 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/MainNavbarContainer.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/MainNavbarContainer.tsx
@@ -18,7 +18,6 @@ import {
getCollectionIcon,
nonPersonalOrArchivedCollection,
} from "metabase/collections/utils";
-import { Modal } from "metabase/common/components/Modal";
import { PLUGIN_TENANTS } from "metabase/plugins";
import { connect, useDispatch, useSelector } from "metabase/redux";
import { logout } from "metabase/redux/auth";
@@ -29,6 +28,7 @@ import {
getUser,
getUserCanWriteToCollections,
} from "metabase/selectors/user";
+import { Modal } from "metabase/ui";
import * as Urls from "metabase/urls";
import type { Collection, User } from "metabase-types/api";
@@ -223,7 +223,15 @@ function MainNavbarContainer({
showExternalCollectionsSection={showExternalCollectionsSection}
/>
- {modal && <Modal onClose={closeModal}>{renderModalContent()}</Modal>}
+ <Modal
+ opened={Boolean(modal)}
+ onClose={closeModal}
+ size="lg"
+ withCloseButton={false}
+ padding={0}
+ >
+ {renderModalContent()}
+ </Modal>
</>
);
}
diff --git a/frontend/src/metabase/new/components/NewModals/NewModals.tsx b/frontend/src/metabase/new/components/NewModals/NewModals.tsx
index 171cf19c9f3..10b5f23afa9 100644
--- a/frontend/src/metabase/new/components/NewModals/NewModals.tsx
+++ b/frontend/src/metabase/new/components/NewModals/NewModals.tsx
@@ -10,7 +10,6 @@ import CreateCollectionModal, {
} from "metabase/collections/containers/CreateCollectionModal";
import { useInitialCollectionId } from "metabase/collections/hooks";
import { CreateDashboardModal } from "metabase/common/CreateDashboard/CreateDashboardModal";
-import { Modal } from "metabase/common/components/Modal";
import { UpgradeModal } from "metabase/common/components/upsells/components/UpgradeModal";
import { STATIC_LEGACY_EMBEDDING_TYPE } from "metabase/embedding/constants";
import {
@@ -24,6 +23,7 @@ import type { SdkIframeEmbedSetupModalProps } from "metabase/plugins";
import { useDispatch, useSelector } from "metabase/redux";
import { closeModal, setOpenModal } from "metabase/redux/ui";
import { getCurrentOpenModalState } from "metabase/selectors/ui";
+import { Modal, PREVENT_AUTOCOMPLETE_CLIPPING_MODAL_PROPS } from "metabase/ui";
import * as Urls from "metabase/urls";
import type { WritebackAction } from "metabase-types/api";
@@ -91,7 +91,14 @@ export const NewModals = withRouter((props: WithRouterProps) => {
);
case "action":
return (
- <Modal wide onClose={handleModalClose} enableTransition={false}>
+ <Modal
+ {...PREVENT_AUTOCOMPLETE_CLIPPING_MODAL_PROPS}
+ opened
+ onClose={handleModalClose}
+ size="95%"
+ withCloseButton={false}
+ padding={0}
+ >
<ActionCreator
onClose={handleModalClose}
onSubmit={handleActionCreated}
diff --git a/frontend/src/metabase/plugins/oss/library.ts b/frontend/src/metabase/plugins/oss/library.ts
index 9c8b530176b..39429e41921 100644
--- a/frontend/src/metabase/plugins/oss/library.ts
+++ b/frontend/src/metabase/plugins/oss/library.ts
@@ -48,6 +48,7 @@ export type UnpublishTablesModalProps = {
};
export type CollectionPermissionsModalProps = {
+ opened: boolean;
collectionId: CollectionId;
namespace?: CollectionNamespace | null;
onClose: () => void;
diff --git a/frontend/src/metabase/plugins/oss/snippets.ts b/frontend/src/metabase/plugins/oss/snippets.ts
index 1230d845e06..ebc85fcce64 100644
--- a/frontend/src/metabase/plugins/oss/snippets.ts
+++ b/frontend/src/metabase/plugins/oss/snippets.ts
@@ -39,6 +39,7 @@ export type SnippetCollectionPickerModalProps = {
};
export type SnippetCollectionPermissionsModalProps = {
+ opened: boolean;
collectionId: CollectionId;
onClose: () => void;
};
diff --git a/frontend/src/metabase/query_builder/components/QueryModals/QueryModals.tsx b/frontend/src/metabase/query_builder/components/QueryModals/QueryModals.tsx
index 4e9e00d6e80..08c7e29fc89 100644
--- a/frontend/src/metabase/query_builder/components/QueryModals/QueryModals.tsx
+++ b/frontend/src/metabase/query_builder/components/QueryModals/QueryModals.tsx
@@ -6,7 +6,6 @@ import _ from "underscore";
import { getDashboard } from "metabase/api";
import { useGetDefaultCollectionId } from "metabase/collections/hooks";
import { CopyModal } from "metabase/common/components/CopyModal";
-import { Modal } from "metabase/common/components/Modal";
import { AddToDashSelectDashModal } from "metabase/common/components/Pickers/AddToDashSelectDashModal";
import { SaveQuestionModal } from "metabase/common/components/SaveQuestionModal";
import { type ToastArgs, useToast } from "metabase/common/hooks";
@@ -29,7 +28,7 @@ import type { QueryBuilderMode } from "metabase/redux/store";
import EditEventModal from "metabase/timelines/questions/containers/EditEventModal";
import MoveEventModal from "metabase/timelines/questions/containers/MoveEventModal";
import NewEventModal from "metabase/timelines/questions/containers/NewEventModal";
-import { Text } from "metabase/ui";
+import { Modal, Text } from "metabase/ui";
import * as Urls from "metabase/urls";
import Question from "metabase-lib/v1/Question";
import type { Card, DashboardTabId } from "metabase-types/api";
@@ -282,19 +281,37 @@ export function QueryModals({
);
case MODAL_TYPES.TURN_INTO_DATASET:
return (
- <Modal small onClose={onCloseModal}>
+ <Modal
+ opened
+ onClose={onCloseModal}
+ size="md"
+ withCloseButton={false}
+ padding={0}
+ >
<NewDatasetModal onClose={onCloseModal} />
</Modal>
);
case MODAL_TYPES.CAN_NOT_CREATE_MODEL:
return (
- <Modal onClose={onCloseModal}>
+ <Modal
+ opened
+ onClose={onCloseModal}
+ size="lg"
+ withCloseButton={false}
+ padding={0}
+ >
<ImpossibleToCreateModelModal onClose={onCloseModal} />
</Modal>
);
case MODAL_TYPES.NEW_EVENT:
return (
- <Modal onClose={onCloseModal}>
+ <Modal
+ opened
+ onClose={onCloseModal}
+ size="lg"
+ withCloseButton={false}
+ padding={0}
+ >
<NewEventModal
cardId={question.id()}
collectionId={question.collectionId()}
@@ -304,13 +321,25 @@ export function QueryModals({
);
case MODAL_TYPES.EDIT_EVENT:
return (
- <Modal onClose={onCloseModal}>
+ <Modal
+ opened
+ onClose={onCloseModal}
+ size="lg"
+ withCloseButton={false}
+ padding={0}
+ >
<EditEventModal eventId={modalContext} onClose={onCloseModal} />
</Modal>
);
case MODAL_TYPES.MOVE_EVENT:
return (
- <Modal onClose={onCloseModal}>
+ <Modal
+ opened
+ onClose={onCloseModal}
+ size="lg"
+ withCloseButton={false}
+ padding={0}
+ >
<MoveEventModal
eventId={modalContext}
collectionId={question.collectionId()}
diff --git a/frontend/src/metabase/routes.tsx b/frontend/src/metabase/routes.tsx
index 1fc367cec7d..993450a00d4 100644
--- a/frontend/src/metabase/routes.tsx
+++ b/frontend/src/metabase/routes.tsx
@@ -177,10 +177,6 @@ export const getRoutes = (store: AppStore) => {
path="comments/:childTargetId"
modal={CommentsSidesheet}
noWrap
- modalProps={{
- enableTransition: false,
- closeOnClickOutside: false,
- }}
/>
</Route>
diff --git a/frontend/src/metabase/timelines/collections/containers/DeleteEventModal/DeleteEventModal.tsx b/frontend/src/metabase/timelines/collections/containers/DeleteEventModal/DeleteEventModal.tsx
index 625e3acd193..e50bbee32ed 100644
--- a/frontend/src/metabase/timelines/collections/containers/DeleteEventModal/DeleteEventModal.tsx
+++ b/frontend/src/metabase/timelines/collections/containers/DeleteEventModal/DeleteEventModal.tsx
@@ -13,7 +13,7 @@ import DeleteEventModal from "metabase/timelines/common/components/DeleteEventMo
import * as Urls from "metabase/urls";
import type { Timeline, TimelineEvent } from "metabase-types/api";
-function DeleteEventModalContainer({ params }: ModalComponentProps) {
+function DeleteEventModalContainer({ params, onClose }: ModalComponentProps) {
const dispatch = useDispatch();
const timelineId = Urls.extractEntityId(params.timelineId);
const eventId = Urls.extractEntityId(params.timelineEventId);
@@ -44,7 +44,12 @@ function DeleteEventModalContainer({ params }: ModalComponentProps) {
}
return (
- <DeleteEventModal event={event} timeline={timeline} onSubmit={onSubmit} />
+ <DeleteEventModal
+ event={event}
+ timeline={timeline}
+ onSubmit={onSubmit}
+ onClose={onClose}
+ />
);
}
diff --git a/frontend/src/metabase/timelines/collections/containers/EditEventModal/EditEventModal.tsx b/frontend/src/metabase/timelines/collections/containers/EditEventModal/EditEventModal.tsx
index 6f83bdbd399..5bfff70d5a6 100644
--- a/frontend/src/metabase/timelines/collections/containers/EditEventModal/EditEventModal.tsx
+++ b/frontend/src/metabase/timelines/collections/containers/EditEventModal/EditEventModal.tsx
@@ -15,7 +15,7 @@ import type { Timeline, TimelineEvent } from "metabase-types/api";
import LoadingAndErrorWrapper from "../../components/LoadingAndErrorWrapper";
-function EditEventModalContainer({ params }: ModalComponentProps) {
+function EditEventModalContainer({ params, onClose }: ModalComponentProps) {
const dispatch = useDispatch();
const archive = useSetArchive();
const timelineId = Urls.extractEntityId(params.timelineId);
@@ -61,6 +61,7 @@ function EditEventModalContainer({ params }: ModalComponentProps) {
timeline={timeline}
onSubmit={onSubmit}
onArchive={onArchive}
+ onClose={onClose}
/>
);
}
diff --git a/frontend/src/metabase/timelines/collections/containers/NewEventModal/NewEventModal.tsx b/frontend/src/metabase/timelines/collections/containers/NewEventModal/NewEventModal.tsx
index a652e05eb76..44ff34ba34e 100644
--- a/frontend/src/metabase/timelines/collections/containers/NewEventModal/NewEventModal.tsx
+++ b/frontend/src/metabase/timelines/collections/containers/NewEventModal/NewEventModal.tsx
@@ -17,7 +17,7 @@ import type {
import LoadingAndErrorWrapper from "../../components/LoadingAndErrorWrapper";
-function NewEventModalContainer({ params }: ModalComponentProps) {
+function NewEventModalContainer({ params, onClose }: ModalComponentProps) {
const dispatch = useDispatch();
const [createTimelineEvent] = useCreateTimelineEventMutation();
const id = Urls.extractEntityId(params.timelineId);
@@ -49,6 +49,7 @@ function NewEventModalContainer({ params }: ModalComponentProps) {
source="collections"
timelines={[timeline]}
onSubmit={onSubmit}
+ onClose={onClose}
/>
);
}
diff --git a/frontend/src/metabase/timelines/collections/routes.tsx b/frontend/src/metabase/timelines/collections/routes.tsx
index c94100c209c..c358ba3ad6c 100644
--- a/frontend/src/metabase/timelines/collections/routes.tsx
+++ b/frontend/src/metabase/timelines/collections/routes.tsx
@@ -1,6 +1,7 @@
import { Fragment } from "react";
import { ModalRoute } from "metabase/hoc/ModalRoute";
+import { NO_ANIMATION_MODAL_PROPS } from "metabase/ui";
import DeleteEventModal from "./containers/DeleteEventModal";
import DeleteTimelineModal from "./containers/DeleteTimelineModal";
@@ -23,46 +24,42 @@ const getRoutes = () => {
{...{
path: "timelines",
modal: TimelineIndexModal,
- // enableMouseEvents lets Mantine's click-outside detection work
- // for the overflow menus inside (UXW-264).
- modalProps: { enableTransition: false, enableMouseEvents: true },
+ modalProps: NO_ANIMATION_MODAL_PROPS,
}}
/>
<ModalRoute
{...{
path: "timelines/new",
modal: NewTimelineModal,
- modalProps: { enableTransition: false },
+ modalProps: NO_ANIMATION_MODAL_PROPS,
}}
/>
<ModalRoute
{...{
path: "timelines/archive",
modal: TimelineListArchiveModal,
- modalProps: { enableTransition: false, enableMouseEvents: true },
+ modalProps: NO_ANIMATION_MODAL_PROPS,
}}
/>
<ModalRoute
{...{
path: "timelines/:timelineId",
modal: TimelineDetailsModal,
- // enableMouseEvents lets Mantine's click-outside detection work
- // for the overflow menus inside (UXW-264).
- modalProps: { enableTransition: false, enableMouseEvents: true },
+ modalProps: NO_ANIMATION_MODAL_PROPS,
}}
/>
<ModalRoute
{...{
path: "timelines/:timelineId/edit",
modal: EditTimelineModal,
- modalProps: { enableTransition: false },
+ modalProps: NO_ANIMATION_MODAL_PROPS,
}}
/>
<ModalRoute
{...{
path: "timelines/:timelineId/move",
modal: MoveTimelineModal,
- modalProps: { enableTransition: false },
+ modalProps: NO_ANIMATION_MODAL_PROPS,
noWrap: true,
}}
/>
@@ -70,49 +67,49 @@ const getRoutes = () => {
{...{
path: "timelines/:timelineId/archive",
modal: TimelineArchiveModal,
- modalProps: { enableTransition: false, enableMouseEvents: true },
+ modalProps: NO_ANIMATION_MODAL_PROPS,
}}
/>
<ModalRoute
{...{
path: "timelines/:timelineId/delete",
modal: DeleteTimelineModal,
- modalProps: { enableTransition: false },
+ modalProps: NO_ANIMATION_MODAL_PROPS,
}}
/>
<ModalRoute
{...{
path: "timelines/new/events/new",
modal: NewEventWithTimelineModal,
- modalProps: { enableTransition: false },
+ modalProps: NO_ANIMATION_MODAL_PROPS,
}}
/>
<ModalRoute
{...{
path: "timelines/:timelineId/events/new",
modal: NewEventModal,
- modalProps: { enableTransition: false },
+ modalProps: NO_ANIMATION_MODAL_PROPS,
}}
/>
<ModalRoute
{...{
path: "timelines/:timelineId/events/:timelineEventId/edit",
modal: EditEventModal,
- modalProps: { enableTransition: false },
+ modalProps: NO_ANIMATION_MODAL_PROPS,
}}
/>
<ModalRoute
{...{
path: "timelines/:timelineId/events/:timelineEventId/move",
modal: MoveEventModal,
- modalProps: { enableTransition: false },
+ modalProps: NO_ANIMATION_MODAL_PROPS,
}}
/>
<ModalRoute
{...{
path: "timelines/:timelineId/events/:timelineEventId/delete",
modal: DeleteEventModal,
- modalProps: { enableTransition: false },
+ modalProps: NO_ANIMATION_MODAL_PROPS,
}}
/>
</Fragment>
diff --git a/frontend/src/metabase/timelines/common/components/EventForm/EventForm.tsx b/frontend/src/metabase/timelines/common/components/EventForm/EventForm.tsx
index 275a0c970c4..85d2d07d800 100644
--- a/frontend/src/metabase/timelines/common/components/EventForm/EventForm.tsx
+++ b/frontend/src/metabase/timelines/common/components/EventForm/EventForm.tsx
@@ -111,7 +111,7 @@ const EventForm = ({
name="name"
label={t`Event name`}
placeholder={t`Product launch`}
- autoFocus
+ data-autofocus
/>
<Flex align="end" gap="md">
<FormDateInput
diff --git a/frontend/src/metabase/timelines/questions/containers/EditEventModal/EditEventModal.tsx b/frontend/src/metabase/timelines/questions/containers/EditEventModal/EditEventModal.tsx
index 4c8be2436a6..3ec976beb6a 100644
--- a/frontend/src/metabase/timelines/questions/containers/EditEventModal/EditEventModal.tsx
+++ b/frontend/src/metabase/timelines/questions/containers/EditEventModal/EditEventModal.tsx
@@ -43,6 +43,7 @@ function EditEventModalContainer({
onSubmitSuccess={onClose}
onArchive={onArchive}
onArchiveSuccess={onClose}
+ onClose={onClose}
/>
);
}
diff --git a/frontend/src/metabase/timelines/questions/containers/NewEventModal/NewEventModal.tsx b/frontend/src/metabase/timelines/questions/containers/NewEventModal/NewEventModal.tsx
index 6a241135a39..21a637999b4 100644
--- a/frontend/src/metabase/timelines/questions/containers/NewEventModal/NewEventModal.tsx
+++ b/frontend/src/metabase/timelines/questions/containers/NewEventModal/NewEventModal.tsx
@@ -62,6 +62,7 @@ function NewEventModalContainer({
collection={collection}
onSubmit={onSubmit}
onSubmitSuccess={onClose}
+ onClose={onClose}
/>
);
}
diff --git a/frontend/src/metabase/ui/components/overlays/HoverCard/index.tsx b/frontend/src/metabase/ui/components/overlays/HoverCard/index.tsx
index 5bc7ecff52d..44e0c5677d1 100644
--- a/frontend/src/metabase/ui/components/overlays/HoverCard/index.tsx
+++ b/frontend/src/metabase/ui/components/overlays/HoverCard/index.tsx
@@ -4,15 +4,22 @@ import {
} from "@mantine/core";
import { PreventEagerPortal } from "metabase/ui";
+import { OverlayStackItem } from "metabase/ui/components/overlays/overlay-stack";
export { hoverCardOverrides } from "./HoverCard.config";
export type { HoverCardDropdownProps, HoverCardProps } from "@mantine/core";
const MantineHoverCardDropdown = MantineHoverCard.Dropdown;
-const HoverCardDropdown = function Dropdown(props: HoverCardDropdownProps) {
+const HoverCardDropdown = function Dropdown({
+ children,
+ ...props
+}: HoverCardDropdownProps) {
return (
<PreventEagerPortal {...props}>
- <MantineHoverCardDropdown {...props} />
+ <MantineHoverCardDropdown {...props}>
+ <OverlayStackItem />
+ {children}
+ </MantineHoverCardDropdown>
</PreventEagerPortal>
);
};
diff --git a/frontend/src/metabase/ui/components/overlays/Menu/MenuDropdown/MenuDropdown.tsx b/frontend/src/metabase/ui/components/overlays/Menu/MenuDropdown/MenuDropdown.tsx
index 3eed4a3f6a4..426f2e43531 100644
--- a/frontend/src/metabase/ui/components/overlays/Menu/MenuDropdown/MenuDropdown.tsx
+++ b/frontend/src/metabase/ui/components/overlays/Menu/MenuDropdown/MenuDropdown.tsx
@@ -1,14 +1,11 @@
import type { MenuDropdownProps } from "@mantine/core";
import { Menu } from "@mantine/core";
-import type { ReactNode, Ref } from "react";
-import { forwardRef, useEffect } from "react";
+import type { Ref } from "react";
+import { forwardRef } from "react";
import { PreventEagerPortal } from "metabase/ui";
-import { useSequencedContentCloseHandler } from "metabase/ui/hooks/use-sequenced-content-close-handler";
+import { OverlayStackItem } from "metabase/ui/components/overlays/overlay-stack";
-// hack to prevent a parent registered in the RENDERED_POPOVERS stack (legacy
-// Modal via OnClickOutsideWrapper) from closing when selecting a Menu.Item
-// remove when the legacy Modal / RENDERED_POPOVERS stack is no longer used (GDGT-2575)
export const MenuDropdown = forwardRef(function MenuDropdown(
{ children, ...props }: MenuDropdownProps,
ref: Ref<HTMLDivElement>,
@@ -16,24 +13,9 @@ export const MenuDropdown = forwardRef(function MenuDropdown(
return (
<PreventEagerPortal {...props}>
<Menu.Dropdown {...props} data-element-id="mantine-popover" ref={ref}>
- <MenuDropdownContent>{children}</MenuDropdownContent>
+ <OverlayStackItem />
+ {children}
</Menu.Dropdown>
</PreventEagerPortal>
);
});
-
-interface MenuDropdownContentProps {
- children?: ReactNode;
-}
-
-function MenuDropdownContent({ children }: MenuDropdownContentProps) {
- const { setupCloseHandler, removeCloseHandler } =
- useSequencedContentCloseHandler();
-
- useEffect(() => {
- setupCloseHandler(document.body, () => undefined);
- return () => removeCloseHandler();
- }, [setupCloseHandler, removeCloseHandler]);
-
- return <>{children}</>;
-}
diff --git a/frontend/src/metabase/ui/components/overlays/Modal/constants.ts b/frontend/src/metabase/ui/components/overlays/Modal/constants.ts
new file mode 100644
index 00000000000..e0a2c1f5b06
--- /dev/null
+++ b/frontend/src/metabase/ui/components/overlays/Modal/constants.ts
@@ -0,0 +1,19 @@
+import type { ModalProps } from "@mantine/core";
+
+export const NO_ANIMATION_MODAL_PROPS: Partial<ModalProps> = {
+ transitionProps: { duration: 0 },
+ styles: {
+ overlay: { animation: "none" },
+ content: { animation: "none" },
+ inner: { animation: "none" },
+ },
+};
+
+// Use on modals that embed a CodeMirror native editor (e.g. the action
+// editor). The modal's enter animation leaves a `transform` on the content,
+// which makes CodeMirror switch its autocomplete popup from `position: fixed`
+// to `absolute` — and the popup then gets clipped by the editor's
+// `overflow: hidden` wrappers. Disabling the animation removes the transform,
+// so the popup stays `fixed` and renders fully.
+export const PREVENT_AUTOCOMPLETE_CLIPPING_MODAL_PROPS =
+ NO_ANIMATION_MODAL_PROPS;
diff --git a/frontend/src/metabase/ui/components/overlays/Modal/index.tsx b/frontend/src/metabase/ui/components/overlays/Modal/index.tsx
index 8e1e6edfc56..fb0c59936a2 100644
--- a/frontend/src/metabase/ui/components/overlays/Modal/index.tsx
+++ b/frontend/src/metabase/ui/components/overlays/Modal/index.tsx
@@ -5,32 +5,46 @@ import {
} from "@mantine/core";
import { PreventEagerPortal } from "metabase/ui";
+import { useGatedCloseProps } from "metabase/ui/components/overlays/overlay-stack";
import { useDisableCommandPalette } from "metabase/ui/hooks/use-disable-command-palette";
export type { ModalProps } from "@mantine/core";
export { useModalsStack } from "@mantine/core";
export * from "./Modal.config";
+export * from "./constants";
export function Modal(props: ModalProps) {
+ const closeProps = useGatedCloseProps(props);
+
useDisableCommandPalette({
disabled: props.opened,
});
return (
<PreventEagerPortal {...props}>
- <MantineModal {...props} />
+ <MantineModal
+ {...props}
+ closeOnClickOutside={closeProps.closeOnClickOutside}
+ closeOnEscape={closeProps.closeOnEscape}
+ />
</PreventEagerPortal>
);
}
function ModalRoot(props: ModalRootProps) {
+ const closeProps = useGatedCloseProps(props);
+
useDisableCommandPalette({
disabled: props.opened,
});
return (
<PreventEagerPortal>
- <MantineModal.Root {...props} />
+ <MantineModal.Root
+ {...props}
+ closeOnClickOutside={closeProps.closeOnClickOutside}
+ closeOnEscape={closeProps.closeOnEscape}
+ />
</PreventEagerPortal>
);
}
diff --git a/frontend/src/metabase/ui/components/overlays/Popover/index.tsx b/frontend/src/metabase/ui/components/overlays/Popover/index.tsx
index e125de2bd50..397e6b3dede 100644
--- a/frontend/src/metabase/ui/components/overlays/Popover/index.tsx
+++ b/frontend/src/metabase/ui/components/overlays/Popover/index.tsx
@@ -1,86 +1,31 @@
import type { PopoverDropdownProps } from "@mantine/core";
import { Popover as MantinePopover } from "@mantine/core";
-import { useMergedRef } from "@mantine/hooks";
import cx from "classnames";
-import { type Ref, type RefObject, forwardRef, useEffect, useRef } from "react";
-import { useLatest } from "react-use";
+import { type Ref, forwardRef } from "react";
import ZIndex from "metabase/css/core/z-index.module.css";
import { PreventEagerPortal } from "metabase/ui";
-import { useSequencedContentCloseHandler } from "metabase/ui/hooks/use-sequenced-content-close-handler";
+import { OverlayStackItem } from "metabase/ui/components/overlays/overlay-stack";
export type { PopoverProps } from "@mantine/core";
export { popoverOverrides } from "./Popover.config";
const MantinePopoverDropdown = MantinePopover.Dropdown;
-type ExtendedPopoverDropdownProps = PopoverDropdownProps & {
- // Registers the dropdown in the RENDERED_POPOVERS stack while it is open, so
- // that a parent registered there (legacy Modal via OnClickOutsideWrapper)
- // does not react to Esc/outside clicks meant for this dropdown. The callback
- // must actually close the popover: inside a legacy Modal the EventSandbox
- // swallows mousedown before it reaches Mantine's document-level
- // closeOnClickOutside listener, so the stack (window capture) is the only
- // thing that can close the popover on an outside click there.
- // TODO: remove when the legacy Modal / RENDERED_POPOVERS stack is no longer used (GDGT-2575)
- setupSequencedCloseHandler?: () => void;
-};
-
-type SequencedCloseHandlerSetupProps = {
- dropdownRef: RefObject<HTMLDivElement>;
- onClose: () => void;
-};
-
-// Rendered inside the dropdown so that it is mounted only while the popover is
-// open — registering on the wrapper itself would permanently occupy the top of
-// the stack and block the parent modal from ever closing.
-// TODO: remove when the legacy Modal / RENDERED_POPOVERS stack is no longer
-// used (GDGT-2575, together with the setupSequencedCloseHandler prop and the
-// dropdownRef/useMergedRef wiring below)
-const SequencedCloseHandlerSetup = ({
- dropdownRef,
- onClose,
-}: SequencedCloseHandlerSetupProps) => {
- const { setupCloseHandler, removeCloseHandler } =
- useSequencedContentCloseHandler();
- const onCloseRef = useLatest(onClose);
-
- useEffect(() => {
- const dropdownEl = dropdownRef.current;
- // the target element, same exclusion as in Mantine's own useClickOutside —
- // a click on the trigger must toggle the popover, not close-and-reopen it
- const targetEl = dropdownEl?.id
- ? document.querySelector(`[aria-controls="${dropdownEl.id}"]`)
- : null;
- setupCloseHandler(dropdownEl, () => onCloseRef.current(), targetEl);
- return () => removeCloseHandler();
- }, [setupCloseHandler, removeCloseHandler, dropdownRef, onCloseRef]);
-
- return null;
-};
-
const PopoverDropdown = forwardRef(function PopoverDropdown(
- { setupSequencedCloseHandler, ...props }: ExtendedPopoverDropdownProps,
+ { children, ...props }: PopoverDropdownProps,
ref: Ref<HTMLDivElement>,
) {
- const dropdownRef = useRef<HTMLDivElement>(null);
- const mergedRef = useMergedRef(ref, dropdownRef);
-
return (
<PreventEagerPortal {...props}>
<MantinePopoverDropdown
{...props}
className={cx(props.className, ZIndex.Overlay)}
data-element-id="mantine-popover"
- ref={mergedRef}
+ ref={ref}
>
- {setupSequencedCloseHandler && (
- <SequencedCloseHandlerSetup
- dropdownRef={dropdownRef}
- onClose={setupSequencedCloseHandler}
- />
- )}
- {props.children}
+ <OverlayStackItem />
+ {children}
</MantinePopoverDropdown>
</PreventEagerPortal>
);
diff --git a/frontend/src/metabase/ui/components/overlays/overlay-stack/index.ts b/frontend/src/metabase/ui/components/overlays/overlay-stack/index.ts
new file mode 100644
index 00000000000..9e9db75e115
--- /dev/null
+++ b/frontend/src/metabase/ui/components/overlays/overlay-stack/index.ts
@@ -0,0 +1,2 @@
+export * from "./overlay-stack";
+export * from "./overlay-stack-provider";
diff --git a/frontend/src/metabase/ui/components/overlays/overlay-stack/overlay-stack-provider.tsx b/frontend/src/metabase/ui/components/overlays/overlay-stack/overlay-stack-provider.tsx
new file mode 100644
index 00000000000..b663f723a3f
--- /dev/null
+++ b/frontend/src/metabase/ui/components/overlays/overlay-stack/overlay-stack-provider.tsx
@@ -0,0 +1,21 @@
+import { type ReactNode, createContext, useState } from "react";
+
+import {
+ type OverlayStackContextStore,
+ createOverlayStackStore,
+} from "./store";
+
+type OverlayStackContextType = OverlayStackContextStore;
+
+export const OverlayStackContext =
+ createContext<OverlayStackContextType | null>(null);
+
+export const OverlayStackProvider = ({ children }: { children: ReactNode }) => {
+ const [store] = useState(createOverlayStackStore);
+
+ return (
+ <OverlayStackContext.Provider value={store}>
+ {children}
+ </OverlayStackContext.Provider>
+ );
+};
diff --git a/frontend/src/metabase/ui/components/overlays/overlay-stack/overlay-stack.tsx b/frontend/src/metabase/ui/components/overlays/overlay-stack/overlay-stack.tsx
new file mode 100644
index 00000000000..d226ced82e0
--- /dev/null
+++ b/frontend/src/metabase/ui/components/overlays/overlay-stack/overlay-stack.tsx
@@ -0,0 +1,95 @@
+import {
+ useContext,
+ useEffect,
+ useId,
+ useState,
+ useSyncExternalStore,
+} from "react";
+import { flushSync } from "react-dom";
+import { useLatest } from "react-use";
+
+import { OverlayStackContext } from "./overlay-stack-provider";
+
+const useOverlayStackContext = () => {
+ const context = useContext(OverlayStackContext);
+ if (!context) {
+ throw new Error(
+ "Overlay components must be rendered within an OverlayStackProvider",
+ );
+ }
+ return context;
+};
+
+const useIsTopmost = (opened: boolean) => {
+ const id = useId();
+ const context = useOverlayStackContext();
+ const currentStack = useSyncExternalStore(
+ context.subscribe,
+ context.getStack,
+ );
+
+ useEffect(() => {
+ if (!opened) {
+ return;
+ }
+ context.push(id);
+ return () => context.remove(id);
+ }, [opened, id, context]);
+
+ return opened && currentStack.at(-1) === id;
+};
+
+// Overlays dismiss on different pointer phases: menus/popovers close on the
+// `mousedown` (pointer down) that lands outside, while modals close on the
+// following `click`. By the time a modal's click fires, the menu above it has
+// already closed and the modal has become topmost — so gating click-outside on
+// the *current* topmost would let the click leak through and close the modal.
+// We instead snapshot topmost-ness at pointer down (before any closing happens)
+// and gate the click against that snapshot.
+const useIsTopmostAtPointerDown = (isTopmost: boolean, opened: boolean) => {
+ const isTopmostRef = useLatest(isTopmost);
+ const [snapshot, setSnapshot] = useState(isTopmost);
+
+ useEffect(() => {
+ if (!opened) {
+ return;
+ }
+ // The snapshot is committed with flushSync so the re-render lands synchronously
+ // within the pointer-down handler, before the `click` fires. A real user leaves
+ // time between the two events for React to re-render on its own, but Cypress
+ // dispatches pointerdown→click in one synchronous burst, so without flushSync
+ // the click would still read the stale snapshot and skip the close.
+ const takeSnapshot = () =>
+ flushSync(() => setSnapshot(isTopmostRef.current));
+ document.addEventListener("pointerdown", takeSnapshot, true);
+ return () =>
+ document.removeEventListener("pointerdown", takeSnapshot, true);
+ }, [opened, isTopmostRef]);
+
+ return snapshot;
+};
+
+type GatedCloseProps = {
+ opened?: boolean;
+ closeOnEscape?: boolean;
+ closeOnClickOutside?: boolean;
+};
+
+export const useGatedCloseProps = ({
+ opened = true,
+ closeOnEscape,
+ closeOnClickOutside,
+}: GatedCloseProps) => {
+ const isTopmost = useIsTopmost(opened);
+ const isTopmostAtPointerDown = useIsTopmostAtPointerDown(isTopmost, opened);
+
+ return {
+ closeOnEscape: isTopmost ? closeOnEscape : false,
+ closeOnClickOutside: isTopmostAtPointerDown ? closeOnClickOutside : false,
+ };
+};
+
+export const OverlayStackItem = () => {
+ useIsTopmost(true);
+ return null;
+};
diff --git a/frontend/src/metabase/ui/components/overlays/overlay-stack/overlay-stack.unit.spec.tsx b/frontend/src/metabase/ui/components/overlays/overlay-stack/overlay-stack.unit.spec.tsx
new file mode 100644
index 00000000000..d5af9f129f9
--- /dev/null
+++ b/frontend/src/metabase/ui/components/overlays/overlay-stack/overlay-stack.unit.spec.tsx
@@ -0,0 +1,117 @@
+import userEvent from "@testing-library/user-event";
+import type { ReactNode } from "react";
+
+import { render, screen, waitFor } from "__support__/ui";
+import { Button, Menu, Modal, Popover } from "metabase/ui";
+
+const OVERLAY_TESTID = "modal-overlay";
+const UPPER_CONTENT = "upper overlay content";
+
+const UPPER_OVERLAYS = [
+ {
+ name: "Menu",
+ node: (
+ <Menu defaultOpened>
+ <Menu.Target>
+ <Button>menu target</Button>
+ </Menu.Target>
+ <Menu.Dropdown>
+ <Menu.Item>{UPPER_CONTENT}</Menu.Item>
+ </Menu.Dropdown>
+ </Menu>
+ ),
+ },
+ {
+ name: "Popover",
+ node: (
+ <Popover defaultOpened>
+ <Popover.Target>
+ <Button>popover target</Button>
+ </Popover.Target>
+ <Popover.Dropdown>{UPPER_CONTENT}</Popover.Dropdown>
+ </Popover>
+ ),
+ },
+];
+
+const setup = (children?: ReactNode) => {
+ const onClose = jest.fn();
+
+ render(
+ <Modal.Root opened onClose={onClose}>
+ <Modal.Overlay data-testid={OVERLAY_TESTID} />
+ <Modal.Content>
+ <Modal.Header>
+ <Modal.Title>Parent modal</Modal.Title>
+ </Modal.Header>
+ <Modal.Body>{children}</Modal.Body>
+ </Modal.Content>
+ </Modal.Root>,
+ );
+
+ return { onClose };
+};
+
+describe("Modal with an overlay above it", () => {
+ it.each(UPPER_OVERLAYS)(
+ "stays open when a $name above it is dismissed by clicking the backdrop",
+ async ({ node }) => {
+ const { onClose } = setup(node);
+ expect(await screen.findByText(UPPER_CONTENT)).toBeInTheDocument();
+
+ await userEvent.click(screen.getByTestId(OVERLAY_TESTID));
+
+ await waitFor(() => {
+ expect(screen.queryByText(UPPER_CONTENT)).not.toBeInTheDocument();
+ });
+ expect(onClose).not.toHaveBeenCalled();
+ },
+ );
+});
+
+describe("Modal with no overlay above it", () => {
+ it("closes when clicking the backdrop", async () => {
+ const { onClose } = setup();
+
+ await userEvent.click(screen.getByTestId(OVERLAY_TESTID));
+
+ expect(onClose).toHaveBeenCalled();
+ });
+
+ it("closes on escape", async () => {
+ const { onClose } = setup();
+
+ await userEvent.keyboard("{Escape}");
+
+ expect(onClose).toHaveBeenCalled();
+ });
+});
+
+describe("Modal stacked under another modal", () => {
+ it("escape closes only the topmost modal", async () => {
+ const onCloseBase = jest.fn();
+ const onCloseTop = jest.fn();
+
+ render(
+ <>
+ <Modal.Root opened onClose={onCloseBase}>
+ <Modal.Overlay />
+ <Modal.Content>
+ <Modal.Title>Base modal</Modal.Title>
+ </Modal.Content>
+ </Modal.Root>
+ <Modal.Root opened onClose={onCloseTop}>
+ <Modal.Overlay />
+ <Modal.Content>
+ <Modal.Title>Top modal</Modal.Title>
+ </Modal.Content>
+ </Modal.Root>
+ </>,
+ );
+
+ await userEvent.keyboard("{Escape}");
+
+ expect(onCloseTop).toHaveBeenCalled();
+ expect(onCloseBase).not.toHaveBeenCalled();
+ });
+});
diff --git a/frontend/src/metabase/ui/components/overlays/overlay-stack/store.ts b/frontend/src/metabase/ui/components/overlays/overlay-stack/store.ts
new file mode 100644
index 00000000000..f3baab361d4
--- /dev/null
+++ b/frontend/src/metabase/ui/components/overlays/overlay-stack/store.ts
@@ -0,0 +1,31 @@
+export type OverlayStackContextStore = {
+ subscribe: (listener: () => void) => () => void;
+ getStack: () => string[];
+ push: (id: string) => void;
+ remove: (id: string) => void;
+};
+
+export const createOverlayStackStore = (): OverlayStackContextStore => {
+ let stack: string[] = [];
+ const listeners = new Set<() => void>();
+
+ const emit = () => listeners.forEach((listener) => listener());
+
+ return {
+ subscribe: (listener) => {
+ listeners.add(listener);
+ return () => {
+ listeners.delete(listener);
+ };
+ },
+ getStack: () => stack,
+ push: (id) => {
+ stack = [...stack, id];
+ emit();
+ },
+ remove: (id) => {
+ stack = stack.filter((stackId) => stackId !== id);
+ emit();
+ },
+ };
+};
diff --git a/frontend/src/metabase/ui/hooks/use-sequenced-content-close-handler.ts b/frontend/src/metabase/ui/hooks/use-sequenced-content-close-handler.ts
deleted file mode 100644
index b80b8c1e9e0..00000000000
--- a/frontend/src/metabase/ui/hooks/use-sequenced-content-close-handler.ts
+++ /dev/null
@@ -1,121 +0,0 @@
-// TODO: delete this file entirely (the RENDERED_POPOVERS stack and all its
-// registrations) when the legacy Modal is migrated to Modal from metabase/ui
-// (GDGT-2575) — grep for useSequencedContentCloseHandler and
-// setupSequencedCloseHandler to find the consumers to clean up
-import { useCallback, useRef } from "react";
-import _ from "underscore";
-
-import { isElement } from "metabase-types/guards";
-
-type PopoverData = {
- contentEl: Element;
- backdropEl?: Element;
- ignoreEl?: Element;
- close: (e: MouseEvent | KeyboardEvent) => void;
-};
-
-export const RENDERED_POPOVERS: PopoverData[] = [];
-
-function isEventInsideElement(e: Event, el: Element) {
- const target = e.composedPath()[0];
- return isElement(target) && el.contains(target);
-}
-
-// An Escape originating inside a Mantine dropdown is handled by Mantine itself
-// (onKeyDownCapture on the dropdown element). It must not also close a stack
-// entry: Mantine closes the dropdown synchronously during the capture phase,
-// so by the time the event bubbles to this stack's document listener the
-// dropdown is already unregistered and a parent modal would wrongly become the
-// topmost entry. composedPath() is frozen at dispatch time, so the origin is
-// still detectable here.
-// TODO: goes away together with this file when the legacy Modal /
-// RENDERED_POPOVERS stack is no longer used (GDGT-2575)
-function isEventInsideMantinePopover(e: Event) {
- const target = e.composedPath()[0];
- return (
- isElement(target) &&
- target.closest('[data-element-id="mantine-popover"]') !== null
- );
-}
-
-export function removePopoverData(popoverData: PopoverData) {
- const index = RENDERED_POPOVERS.indexOf(popoverData);
- if (index >= 0) {
- RENDERED_POPOVERS.splice(index, 1);
- }
-}
-
-export function shouldClosePopover(
- e: MouseEvent | KeyboardEvent,
- popoverData: PopoverData,
-) {
- const mostRecentPopover = _.last(RENDERED_POPOVERS);
-
- if (e instanceof MouseEvent) {
- return (
- mostRecentPopover &&
- mostRecentPopover === popoverData &&
- !isEventInsideElement(e, mostRecentPopover.contentEl) &&
- (!popoverData.backdropEl ||
- isEventInsideElement(e, popoverData.backdropEl)) &&
- (!popoverData.ignoreEl || !isEventInsideElement(e, popoverData.ignoreEl))
- );
- }
-
- if (e instanceof KeyboardEvent) {
- return (
- mostRecentPopover &&
- mostRecentPopover === popoverData &&
- e.key === "Escape" &&
- !isEventInsideMantinePopover(e)
- );
- }
-
- console.warn("Unsupported event type", e);
- return false;
-}
-
-export function useSequencedContentCloseHandler() {
- const popoverDataRef = useRef<PopoverData>();
-
- const handleEvent = useCallback((e: MouseEvent | KeyboardEvent) => {
- if (
- popoverDataRef.current &&
- shouldClosePopover(e, popoverDataRef.current)
- ) {
- popoverDataRef.current.close(e);
- }
- }, []);
-
- const removeCloseHandler = useCallback(() => {
- if (popoverDataRef.current) {
- removePopoverData(popoverDataRef.current);
- popoverDataRef.current = undefined;
- }
-
- document.removeEventListener("keydown", handleEvent);
- window.removeEventListener("mousedown", handleEvent, true);
- }, [handleEvent]);
-
- const setupCloseHandler = useCallback(
- (
- contentEl: Element | null,
- close: () => void,
- ignoreEl?: Element | null,
- ) => {
- removeCloseHandler();
-
- if (isElement(contentEl)) {
- const popover = { contentEl, close, ignoreEl: ignoreEl ?? undefined };
- RENDERED_POPOVERS.push(popover);
- popoverDataRef.current = popover;
-
- document.addEventListener("keydown", handleEvent);
- window.addEventListener("mousedown", handleEvent, true);
- }
- },
- [handleEvent, removeCloseHandler],
- );
-
- return { setupCloseHandler, removeCloseHandler };
-}
diff --git a/frontend/test/__support__/ui.tsx b/frontend/test/__support__/ui.tsx
index 3a6315674f9..94e61d06075 100644
--- a/frontend/test/__support__/ui.tsx
+++ b/frontend/test/__support__/ui.tsx
@@ -35,6 +35,7 @@ import { getMetabaseCssVariables } from "metabase/styled-components/theme/css-va
import type { MantineThemeOverride } from "metabase/ui";
import { PortalContainer, ThemeProvider, useMantineTheme } from "metabase/ui";
import { mutateColors } from "metabase/ui/colors/colors";
+import { OverlayStackProvider } from "metabase/ui/components/overlays/overlay-stack";
import { ThemeProviderContext } from "metabase/ui/components/theme/ThemeProvider/context";
import MetabaseSettings from "metabase/utils/settings";
@@ -280,24 +281,26 @@ export function TestWrapper({
<MetabaseReduxProvider store={store}>
<MaybeDNDProvider hasDND={withDND}>
<AppColorSchemeProvider onUpdateColorScheme={handleUpdateColorScheme}>
- <ThemeProviderContext.Provider value={{ withCssVariables }}>
- <ThemeProvider
- theme={theme}
- resolvedColorScheme={displayTheme ?? "light"}
- whitelabelColors={whitelabelColors}
- onUpdateWhitelabelColors={handleUpdateWhitelabelColors}
- >
- <GlobalStylesForTest />
- {createPortal(<PortalContainer />, document.body)}
-
- <MaybeKBar hasKBar={withKBar}>
- <MaybeRouter hasRouter={withRouter} history={history}>
- {children}
- </MaybeRouter>
- </MaybeKBar>
- {withUndos && <UndoListing />}
- </ThemeProvider>
- </ThemeProviderContext.Provider>
+ <OverlayStackProvider>
+ <ThemeProviderContext.Provider value={{ withCssVariables }}>
+ <ThemeProvider
+ theme={theme}
+ resolvedColorScheme={displayTheme ?? "light"}
+ whitelabelColors={whitelabelColors}
+ onUpdateWhitelabelColors={handleUpdateWhitelabelColors}
+ >
+ <GlobalStylesForTest />
+ {createPortal(<PortalContainer />, document.body)}
+
+ <MaybeKBar hasKBar={withKBar}>
+ <MaybeRouter hasRouter={withRouter} history={history}>
+ {children}
+ </MaybeRouter>
+ </MaybeKBar>
+ {withUndos && <UndoListing />}
+ </ThemeProvider>
+ </ThemeProviderContext.Provider>
+ </OverlayStackProvider>
</AppColorSchemeProvider>
</MaybeDNDProvider>
</MetabaseReduxProvider>
@@ -477,12 +480,14 @@ const ThemeProviderWrapper = ({
children,
...props
}: React.PropsWithChildren) => (
- <ThemeProviderContext.Provider value={{ withCssVariables: false }}>
- <ThemeProvider {...props}>
- {createPortal(<PortalContainer />, document.body)}
- {children}
- </ThemeProvider>
- </ThemeProviderContext.Provider>
+ <OverlayStackProvider>
+ <ThemeProviderContext.Provider value={{ withCssVariables: false }}>
+ <ThemeProvider {...props}>
+ {createPortal(<PortalContainer />, document.body)}
+ {children}
+ </ThemeProvider>
+ </ThemeProviderContext.Provider>
+ </OverlayStackProvider>
);
export function renderWithTheme(children: React.ReactElement) {