Skip to content

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

feat: improve mention menu in metabot (#69650)

Maksym Yakubychea89a862ecca
diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/MetabotChatEditor.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/MetabotChatEditor.unit.spec.tsx
index 1c2b5e7abb0..5ea6c0f7976 100644
--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/MetabotChatEditor.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/MetabotChatEditor.unit.spec.tsx
@@ -1,17 +1,24 @@
-import { screen } from "@testing-library/react";
+import { screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
+import fetchMock from "fetch-mock";
import { setupEnterprisePlugins } from "__support__/enterprise";
import {
setupCardEndpoints,
- setupDatabaseEndpoints,
+ setupCollectionByIdEndpoint,
+ setupDatabasesEndpoints,
} from "__support__/server-mocks";
import { setupSearchEndpoints } from "__support__/server-mocks/search";
import { mockSettings } from "__support__/settings";
import { renderWithProviders } from "__support__/ui";
+import { ROOT_COLLECTION } from "metabase/entities/collections";
import type { SuggestionModel } from "metabase/rich_text_editing/tiptap/extensions/shared/types";
-import { createMockCard, createMockUser } from "metabase-types/api/mocks";
-import { createSampleDatabase } from "metabase-types/api/mocks/presets";
+import {
+ createMockCard,
+ createMockCollection,
+ createMockDatabase,
+ createMockUser,
+} from "metabase-types/api/mocks";
import { createMockSearchResult } from "metabase-types/api/mocks/search";
import { createMockState } from "metabase-types/store/mocks";
@@ -33,9 +40,29 @@ const defaultProps = {
},
};
-const setup = (props = {}) => {
+// "fetch-mock" can accept an array, the types are incorrect
+const asFetchMockModelParams = (models: string[]) =>
+ models as unknown as string;
+
+const setup = (
+ props = {},
+ {
+ searchItems = [],
+ }: { searchItems?: ReturnType<typeof createMockSearchResult>[] } = {},
+) => {
setupEnterprisePlugins();
setupCardEndpoints(createMockCard({ id: 123, name: "Test Model" }));
+ setupDatabasesEndpoints(
+ [createMockDatabase({ id: 1, name: "DB 1" })],
+ {},
+ {
+ "can-query": true,
+ },
+ );
+ setupCollectionByIdEndpoint({
+ collections: [createMockCollection(ROOT_COLLECTION)],
+ });
+ setupSearchEndpoints(searchItems);
const settings = mockSettings({ "site-url": "http://localhost:3000" });
return renderWithProviders(
@@ -52,7 +79,7 @@ const setup = (props = {}) => {
const getEditor = () =>
// eslint-disable-next-line testing-library/no-node-access
document.querySelector('[contenteditable="true"]')! as HTMLElement;
-const getPopup = () => screen.findByTestId("mention-suggestions-popup");
+const getPopup = () => screen.findByTestId("mini-picker");
describe("MetabotChatEditor", () => {
it("should convert text value to formatted tiptap", async () => {
@@ -88,72 +115,113 @@ describe("MetabotChatEditor", () => {
expect(await getPopup()).toBeInTheDocument();
});
- it("should show available models when @ is typed", async () => {
+ it("should show browse all when @ is typed", async () => {
setup();
await userEvent.type(getEditor(), "@");
const popup = await getPopup();
expect(popup).toBeInTheDocument();
- expect(await screen.findByText("Table")).toBeInTheDocument();
- expect(await screen.findByText("Database")).toBeInTheDocument();
- expect(await screen.findByText("Collection")).toBeInTheDocument();
+ expect(await screen.findByText("Browse all")).toBeInTheDocument();
});
- it("should filter available models when @d is typed", async () => {
- setup();
-
- await userEvent.type(getEditor(), "@d");
-
- const popup = await getPopup();
- expect(popup).toBeInTheDocument();
- expect(await screen.findByText("Database")).toBeInTheDocument();
- expect(screen.queryByText("Table")).not.toBeInTheDocument();
+ it("should query search endpoint when typing mention query", async () => {
+ setup(
+ {},
+ {
+ searchItems: [
+ createMockSearchResult({
+ id: 1234,
+ name: "Sample card",
+ model: "card",
+ }),
+ ],
+ },
+ );
+
+ await userEvent.type(getEditor(), "@sample");
+
+ await waitFor(() => {
+ expect(
+ fetchMock.callHistory.called("path:/api/search", {
+ query: { q: "sample" },
+ }),
+ ).toBeTruthy();
+ });
});
- it("should only search selected @mention model when selected", async () => {
- const db = createSampleDatabase();
- setupDatabaseEndpoints(db);
- setupSearchEndpoints([
- createMockSearchResult({
- id: db.id,
- name: db.name,
- model: "database",
- }),
- ]);
- setup();
-
- await userEvent.type(getEditor(), "@d{Enter}Sample");
- expect(getEditor()).toHaveTextContent("@Sample");
-
- expect(await screen.findByText("Sample Database")).toBeInTheDocument();
+ it("should search all models if @mention input doesn't match any search model name", async () => {
+ setup(
+ {},
+ {
+ searchItems: [
+ createMockSearchResult({ id: 1, name: "Test Card", model: "card" }),
+ createMockSearchResult({
+ id: 2,
+ name: "Test Dashboard",
+ model: "dashboard",
+ }),
+ createMockSearchResult({
+ id: 3,
+ name: "Test Collection",
+ model: "collection",
+ }),
+ ],
+ },
+ );
- await userEvent.keyboard("{Enter}");
+ await userEvent.type(getEditor(), "@test");
- expect(getEditor()).toHaveTextContent("Sample Database");
+ await waitFor(() =>
+ expect(
+ fetchMock.callHistory.calls("path:/api/search").length,
+ ).toBeGreaterThan(0),
+ );
+
+ await waitFor(() => {
+ expect(
+ fetchMock.callHistory.called("path:/api/search", {
+ query: {
+ q: "test",
+ models: asFetchMockModelParams([
+ "table",
+ "card",
+ "dashboard",
+ "collection",
+ ]),
+ },
+ }),
+ ).toBeTruthy();
+ });
});
- it("should search all models if @mention input doesn't match any search model name", async () => {
- setupSearchEndpoints([
- createMockSearchResult({ id: 1, name: "Test Card", model: "card" }),
- createMockSearchResult({
- id: 2,
- name: "Test Dashboard",
- model: "dashboard",
- }),
- createMockSearchResult({
- id: 3,
- name: "Test Collection",
- model: "collection",
- }),
- ]);
- setup();
+ it("requests search with allowed models for @mentions", async () => {
+ setup(
+ {},
+ {
+ searchItems: [
+ createMockSearchResult({ id: 1, name: "Test card", model: "card" }),
+ ],
+ },
+ );
await userEvent.type(getEditor(), "@test");
- expect(await screen.findByText("Test Card")).toBeInTheDocument();
- expect(await screen.findByText("Test Dashboard")).toBeInTheDocument();
- expect(await screen.findByText("Test Collection")).toBeInTheDocument();
+ await waitFor(() => {
+ expect(
+ fetchMock.callHistory.called("path:/api/search", {
+ query: {
+ q: "test",
+ models: asFetchMockModelParams([
+ "table",
+ "card",
+ "dashboard",
+ "collection",
+ ]),
+ },
+ }),
+ ).toBeTruthy();
+ });
});
it("should handle paste events with metabase protocol links", async () => {
diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/hooks/use-metabot-sql-suggestion.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/hooks/use-metabot-sql-suggestion.tsx
index a20455183fe..7358ff9a8eb 100644
--- a/enterprise/frontend/src/metabase-enterprise/metabot/hooks/use-metabot-sql-suggestion.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/metabot/hooks/use-metabot-sql-suggestion.tsx
@@ -94,7 +94,7 @@ export function useMetabotSQLSuggestion({
}, [dispatch, bufferId]);
const suggestionModels: SuggestionModel[] = useMemo(
- () => ["dataset", "card", "table"],
+ () => ["dataset", "table"],
[],
);
diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/EntityPickerModal.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/EntityPickerModal.tsx
index 30eed10ff75..5d84268718c 100644
--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/EntityPickerModal.tsx
+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/EntityPickerModal.tsx
@@ -60,6 +60,7 @@ export type EntityPickerModalProps = {
export function EntityPickerModal({
title = t`Choose an item`,
+ searchQuery: initialSearchQuery,
options,
onClose,
onChange,
@@ -67,7 +68,9 @@ export function EntityPickerModal({
}: EntityPickerModalProps) {
const [modalContentMinWidth, setModalContentMinWidth] = useState(920);
const modalContentRef = useRef<HTMLDivElement | null>(null);
- const [searchQuery, setSearchQuery] = useState<string>("");
+ const [searchQuery, setSearchQuery] = useState<string>(
+ initialSearchQuery || "",
+ );
const [
isNewCollectionDialogOpen,
{ open: openNewCollectionDialog, close: closeNewCollectionDialog },
diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/EntityPickerModal.unit.spec.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/EntityPickerModal.unit.spec.tsx
index b67f9659172..4046d255656 100644
--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/EntityPickerModal.unit.spec.tsx
+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/EntityPickerModal.unit.spec.tsx
@@ -432,6 +432,14 @@ describe("EntityPickerModal", () => {
await expectActiveItem('Search results for "My"');
});
+ it("should prefill the search input when searchQuery is provided", async () => {
+ await setup({ searchQuery: "My prefilled query" });
+
+ expect(await screen.findByPlaceholderText("Search…")).toHaveValue(
+ "My prefilled query",
+ );
+ });
+
it("should return to previous location when clearing the search input", async () => {
await setup();
await userEvent.click(await screen.findByText("Our analytics"));
diff --git a/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPicker/MiniPicker.tsx b/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPicker/MiniPicker.tsx
index c44b2e13f21..18cb5d0170c 100644
--- a/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPicker/MiniPicker.tsx
+++ b/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPicker/MiniPicker.tsx
@@ -1,6 +1,7 @@
-import { useCallback, useEffect, useMemo } from "react";
+import { type Ref, useCallback, useEffect, useMemo } from "react";
import { PLUGIN_LIBRARY } from "metabase/plugins";
+import type { MenuDropdownProps } from "metabase/ui";
import { Box, Menu } from "metabase/ui";
import type { DataPickerValue } from "../../../DataPicker";
@@ -26,6 +27,11 @@ export type MiniPickerProps = {
onBrowseAll?: () => void;
shouldHide?: (item: MiniPickerItem | unknown) => boolean;
shouldShowLibrary?: boolean;
+ children?: React.ReactNode;
+ menuDropdownProps?: MenuDropdownProps;
+ closeOnClickOutside?: boolean;
+ menuDropdownRef?: Ref<HTMLDivElement>;
+ className?: string;
};
export function MiniPicker({
@@ -39,6 +45,11 @@ export function MiniPicker({
trapFocus = false,
shouldHide,
shouldShowLibrary = true,
+ children = <Box />,
+ menuDropdownProps,
+ closeOnClickOutside = true,
+ menuDropdownRef,
+ className,
}: MiniPickerProps) {
const { data: libraryCollection } = PLUGIN_LIBRARY.useGetLibraryCollection();
@@ -90,22 +101,25 @@ export function MiniPicker({
onChange={onClose}
closeOnItemClick={false}
clickOutsideEvents={["mousedown", "touchstart"]}
+ closeOnClickOutside={closeOnClickOutside}
position="bottom-start"
// menuItemTabIndex={-1}
trapFocus={false}
>
- <Menu.Target>
- <Box />
- </Menu.Target>
+ <Menu.Target>{children}</Menu.Target>
<Menu.Dropdown
- mt="xl"
- ml="-1rem"
px={0}
py="sm"
data-testid="mini-picker"
+ {...menuDropdownProps}
+ ref={menuDropdownRef}
>
- {isLoadingPath ? <MiniPickerListLoader /> : <MiniPickerPane />}
+ {isLoadingPath ? (
+ <MiniPickerListLoader />
+ ) : (
+ <MiniPickerPane className={className} />
+ )}
</Menu.Dropdown>
</Menu>
</MiniPickerContext.Provider>
diff --git a/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPickerItem.module.css b/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPickerItem.module.css
new file mode 100644
index 00000000000..c3ee95a09e6
--- /dev/null
+++ b/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPickerItem.module.css
@@ -0,0 +1,17 @@
+.section {
+ min-width: 0;
+ overflow: hidden;
+}
+
+.rightSection[data-position="right"] {
+ min-width: 0;
+ overflow: hidden;
+ flex-basis: 40%;
+ justify-content: start;
+}
+
+.leftSection {
+ min-width: 0;
+ overflow: hidden;
+ flex-basis: 60%;
+}
diff --git a/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPickerItem.tsx b/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPickerItem.tsx
index 3b749a533b3..902bbce5b29 100644
--- a/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPickerItem.tsx
+++ b/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPickerItem.tsx
@@ -7,6 +7,8 @@ import type {
MiniPickerItem as MiniPickerItemType,
} from "../types";
+import styles from "./MiniPickerItem.module.css";
+
export const MiniPickerItem = ({
model,
name,
@@ -29,9 +31,13 @@ export const MiniPickerItem = ({
}
rightSection={isFolder ? <Icon name="chevronright" /> : undefined}
onClick={onClick}
+ classNames={{
+ itemLabel: styles.section,
+ itemSection: styles.section,
+ }}
{...menuItemProps}
>
- <Ellipsified maw={isFolder ? "13rem" : "16rem"}>{name}</Ellipsified>
+ <Ellipsified>{name}</Ellipsified>
</Menu.Item>
</Box>
);
diff --git a/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPickerItemList.tsx b/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPickerItemList.tsx
index f7d770426a4..ae12e25ba82 100644
--- a/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPickerItemList.tsx
+++ b/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPickerItemList.tsx
@@ -38,6 +38,7 @@ import type {
} from "../types";
import { MiniPickerItem } from "./MiniPickerItem";
+import styles from "./MiniPickerItem.module.css";
export function MiniPickerItemList() {
const { path, searchQuery } = useMiniPickerContext();
@@ -364,6 +365,10 @@ function SearchItemList({ query }: { query: string }) {
onChange(item);
}}
rightSection={<LocationInfo item={item} />}
+ classNames={{
+ itemLabel: styles.leftSection,
+ itemSection: styles.rightSection,
+ }}
/>
);
})}
@@ -419,10 +424,10 @@ const LocationInfo = ({ item }: { item: MiniPickerPickableItem }) => {
});
return (
- <Flex gap="xs" align="center">
- {iconProps && <Icon {...iconProps} size={12} />}
- <Text size="sm" c="text-secondary">
- <Ellipsified maw="18rem">{itemText}</Ellipsified>
+ <Flex gap="xs" align="center" ml="auto" style={{ overflow: "hidden" }}>
+ {iconProps && <Icon {...iconProps} size={12} miw={12} />}
+ <Text size="sm" c="text-secondary" miw="0">
+ <Ellipsified>{itemText}</Ellipsified>
</Text>
</Flex>
);
diff --git a/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPickerPane.tsx b/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPickerPane.tsx
index 09a9e6eb849..dc2dad13d11 100644
--- a/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPickerPane.tsx
+++ b/frontend/src/metabase/common/components/Pickers/MiniPicker/components/MiniPickerPane.tsx
@@ -6,13 +6,18 @@ import { MiniPickerFooter } from "./MiniPickerFooter";
import { MiniPickerHeader } from "./MiniPickerHeader";
import { MiniPickerItemList } from "./MiniPickerItemList";
-export function MiniPickerPane() {
+export function MiniPickerPane({ className }: { className?: string }) {
const { path, searchQuery } = useMiniPickerContext();
const isRoot = path.length === 0;
return (
- <Stack mah="30rem" w={searchQuery ? "40rem" : "20rem"} gap={0}>
+ <Stack
+ mah="30rem"
+ w={searchQuery ? "40rem" : "20rem"}
+ gap={0}
+ className={className}
+ >
{!isRoot && !searchQuery && <MiniPickerHeader />}
<MiniPickerItemList />
{(isRoot || searchQuery) && <MiniPickerFooter />}
diff --git a/frontend/src/metabase/metabot/components/MetabotInlineSQLPrompt/MetabotInlineSQLPrompt.tsx b/frontend/src/metabase/metabot/components/MetabotInlineSQLPrompt/MetabotInlineSQLPrompt.tsx
index 67fe561b31b..cce45a5bd48 100644
--- a/frontend/src/metabase/metabot/components/MetabotInlineSQLPrompt/MetabotInlineSQLPrompt.tsx
+++ b/frontend/src/metabase/metabot/components/MetabotInlineSQLPrompt/MetabotInlineSQLPrompt.tsx
@@ -114,7 +114,7 @@ export const MetabotInlineSQLPrompt = ({
onStop={handleClose}
suggestionConfig={{
suggestionModels,
- searchOptions: databaseId ? { table_db_id: databaseId } : undefined,
+ onlyDatabaseId: databaseId ?? undefined,
}}
/>
</Box>
diff --git a/frontend/src/metabase/metabot/components/MetabotPromptInput/MetabotPromptInput.tsx b/frontend/src/metabase/metabot/components/MetabotPromptInput/MetabotPromptInput.tsx
index 20934f2401f..95ca31db3cf 100644
--- a/frontend/src/metabase/metabot/components/MetabotPromptInput/MetabotPromptInput.tsx
+++ b/frontend/src/metabase/metabot/components/MetabotPromptInput/MetabotPromptInput.tsx
@@ -12,16 +12,16 @@ import { t } from "ttag";
import { useSelector } from "metabase/lib/redux";
import type { MetabotPromptInputRef } from "metabase/metabot";
-import { createMentionSuggestion } from "metabase/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion";
import {
MetabotMentionExtension,
MetabotMentionPluginKey,
} from "metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotMentionExtension";
+import { createMetabotMentionSuggestionNew } from "metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestionNew";
import { SmartLink } from "metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode";
import type { SuggestionModel } from "metabase/rich_text_editing/tiptap/extensions/shared/types";
-import type { EntitySearchOptions } from "metabase/rich_text_editing/tiptap/extensions/shared/useEntitySearch";
-import { createSuggestionRenderer } from "metabase/rich_text_editing/tiptap/extensions/suggestionRenderer";
+import { createBareSuggestionRenderer } from "metabase/rich_text_editing/tiptap/extensions/suggestionRenderer";
import { getSetting } from "metabase/selectors/settings";
+import type { DatabaseId } from "metabase-types/api";
import S from "./MetabotPromptInput.module.css";
import {
@@ -40,7 +40,7 @@ export interface MetabotPromptInputProps {
onStop: () => void;
suggestionConfig: {
suggestionModels: SuggestionModel[];
- searchOptions?: EntitySearchOptions;
+ onlyDatabaseId?: DatabaseId;
};
}
export const MetabotPromptInput = forwardRef<
@@ -76,12 +76,10 @@ export const MetabotPromptInput = forwardRef<
}),
MetabotMentionExtension.configure({
suggestion: {
- render: createSuggestionRenderer(
- createMentionSuggestion({
+ render: createBareSuggestionRenderer(
+ createMetabotMentionSuggestionNew({
searchModels: suggestionConfig.suggestionModels,
- searchOptions: suggestionConfig.searchOptions,
- canFilterSearchModels: true,
- canBrowseAll: false,
+ onlyDatabaseId: suggestionConfig.onlyDatabaseId,
}),
),
},
@@ -132,13 +130,15 @@ export const MetabotPromptInput = forwardRef<
},
},
handleKeyDown: (view, event) => {
- if (event.key === "Enter") {
+ if (event.key === "Escape" || event.key === "Enter") {
// Defer enter handling to mention UI if open
const mentionState = MetabotMentionPluginKey.getState(view.state);
if (mentionState?.active) {
return false; // Let the suggestion system handle it
}
+ }
+ if (event.key === "Enter") {
// Check for any modifier keys (shift, ctrl, meta, alt)
const isModifiedKeyPress =
event.shiftKey || event.ctrlKey || event.metaKey || event.altKey;
diff --git a/frontend/src/metabase/metabot/components/MetabotPromptInput/MetabotPromptInput.unit.spec.tsx b/frontend/src/metabase/metabot/components/MetabotPromptInput/MetabotPromptInput.unit.spec.tsx
index 7026e6302e6..945d3bc1dfb 100644
--- a/frontend/src/metabase/metabot/components/MetabotPromptInput/MetabotPromptInput.unit.spec.tsx
+++ b/frontend/src/metabase/metabot/components/MetabotPromptInput/MetabotPromptInput.unit.spec.tsx
@@ -3,25 +3,24 @@ import userEvent from "@testing-library/user-event";
import type { EditorState } from "@tiptap/pm/state";
import { createRef } from "react";
+import {
+ setupCollectionByIdEndpoint,
+ setupDatabasesEndpoints,
+} from "__support__/server-mocks";
import { mockSettings } from "__support__/settings";
import { renderWithProviders } from "__support__/ui";
+import { ROOT_COLLECTION } from "metabase/entities/collections";
import type { MetabotPromptInputRef } from "metabase/metabot";
import { MetabotMentionPluginKey } from "metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotMentionExtension";
import type { SuggestionModel } from "metabase/rich_text_editing/tiptap/extensions/shared/types";
+import {
+ createMockCollection,
+ createMockDatabase,
+} from "metabase-types/api/mocks";
import { createMockState } from "metabase-types/store/mocks";
import { MetabotPromptInput } from "./MetabotPromptInput";
-jest.mock(
- "metabase/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion",
- () => ({
- createMentionSuggestion: () =>
- function MockMentionSuggestion() {
- return <div aria-label="Mention Dialog" role="dialog" />;
- },
- }),
-);
-
const defaultProps = {
value: "",
disabled: false,
@@ -34,6 +33,12 @@ const defaultProps = {
const setup = (props = {}) => {
const settings = mockSettings({ "site-url": "http://localhost:3000" });
+ const rootCollection = createMockCollection(ROOT_COLLECTION);
+
+ setupDatabasesEndpoints([createMockDatabase({ id: 1, name: "DB 1" })]);
+ setupCollectionByIdEndpoint({
+ collections: [rootCollection],
+ });
return renderWithProviders(
<MetabotPromptInput {...defaultProps} {...props} autoFocus />,
@@ -93,12 +98,12 @@ describe("MetabotPromptInput", () => {
await userEvent.type(getEditor(), "@");
- expect(await screen.findByLabelText("Mention Dialog")).toBeInTheDocument();
+ expect(await screen.findByTestId("mini-picker")).toBeInTheDocument();
await userEvent.keyboard("{Escape}");
await waitFor(() => {
- expect(screen.queryByLabelText("Mention Dialog")).not.toBeInTheDocument();
+ expect(screen.queryByTestId("mini-picker")).not.toBeInTheDocument();
});
});
});
diff --git a/frontend/src/metabase/querying/notebook/components/NotebookDataPicker/NotebookDataPicker.tsx b/frontend/src/metabase/querying/notebook/components/NotebookDataPicker/NotebookDataPicker.tsx
index 8c9252546db..6aff894f1b6 100644
--- a/frontend/src/metabase/querying/notebook/components/NotebookDataPicker/NotebookDataPicker.tsx
+++ b/frontend/src/metabase/querying/notebook/components/NotebookDataPicker/NotebookDataPicker.tsx
@@ -238,6 +238,10 @@ function ModernDataPicker({
}}
shouldHide={shouldHide}
shouldShowLibrary={shouldShowLibrary}
+ menuDropdownProps={{
+ mt: "xl",
+ ml: "-1rem",
+ }}
/>
{isOpened && isBrowsing && (
<DataPickerModal
diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotMentionExtension.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotMentionExtension.tsx
index d398c7aabf0..8c3407206ab 100644
--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotMentionExtension.tsx
+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotMentionExtension.tsx
@@ -12,7 +12,7 @@ export interface MentionOptions {
suggestion: Partial<SuggestionOptions>;
}
-interface MentionProps {
+export interface MentionProps {
type?: string;
id?: number | string;
model?: string;
diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.module.css
new file mode 100644
index 00000000000..89f45a74fc0
--- /dev/null
+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.module.css
@@ -0,0 +1,3 @@
+.miniPicker {
+ max-width: 29.125rem;
+}
diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.tsx
index f530c13e7ca..69222c12a30 100644
--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.tsx
+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.tsx
@@ -162,4 +162,5 @@ const MetabotMentionSuggestionComponent = forwardRef<
);
});
+// @deprecated only supports databases, use `MetabotMentionSuggestionNew` instead
export const MetabotMentionSuggestion = MetabotMentionSuggestionComponent;
diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestionNew.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestionNew.tsx
new file mode 100644
index 00000000000..422299d4ceb
--- /dev/null
+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestionNew.tsx
@@ -0,0 +1,326 @@
+import { useClickOutside } from "@mantine/hooks";
+import {
+ forwardRef,
+ useCallback,
+ useImperativeHandle,
+ useMemo,
+ useState,
+} from "react";
+import { match } from "ts-pattern";
+import { t } from "ttag";
+
+import {
+ EntityPickerModal,
+ MiniPicker,
+ type OmniPickerItem,
+} from "metabase/common/components/Pickers";
+import { shouldDisableItemNotInDb } from "metabase/common/components/Pickers/DataPicker";
+import type {
+ MiniPickerItem,
+ MiniPickerPickableItem,
+} from "metabase/common/components/Pickers/MiniPicker/types";
+import type { DatabaseId } from "metabase-types/api";
+
+import { ExternalMenuTarget } from "../shared/ExternalMenuTarget";
+import type { SuggestionModel } from "../shared/types";
+import type { EntitySearchOptions } from "../shared/useEntitySearch";
+import type {
+ BareSuggestionRendererProps,
+ BareSuggestionRendererRef,
+} from "../suggestionRenderer";
+
+import type { MentionProps } from "./MetabotMentionExtension";
+import styles from "./MetabotSuggestion.module.css";
+
+interface MetabotMentionSuggestionPropsBase {
+ searchModels?: SuggestionModel[];
+ searchOptions?: EntitySearchOptions;
+ onlyDatabaseId?: DatabaseId;
+}
+export type MetabotMentionSuggestionProps = MetabotMentionSuggestionPropsBase &
+ BareSuggestionRendererProps<unknown, MentionProps>;
+
+const MetabotMentionSuggestionComponent = forwardRef<
+ BareSuggestionRendererRef,
+ MetabotMentionSuggestionProps
+>(function MentionSuggestionComponent(
+ {
+ items: _items,
+ command,
+ editor,
+ range: _range,
+ query,
+ searchModels,
+ onlyDatabaseId,
+ decorationNode,
+ onClose,
+ },
+ ref,
+) {
+ const [isBrowsing, setIsBrowsing] = useState(false);
+
+ const onSelectEntity = useCallback(
+ (item: OmniPickerItem) => {
+ command({
+ id: item.id,
+ model: item.model,
+ label: item.name,
+ });
+ },
+ [command],
+ );
+
+ const closeOnClickOutside = !isBrowsing;
+ const [menuDropdownDom, setMenuDropdownDom] = useState<HTMLDivElement | null>(
+ null,
+ );
+ const menuDropdownRef = useCallback((node: HTMLDivElement | null) => {
+ setMenuDropdownDom(node);
+ }, []);
+
+ const { onKeyDown, onFocus } = useFakeKeyboardHandler(menuDropdownDom);
+
+ useImperativeHandle(ref, () => ({
+ onKeyDown: ({ event }: { event: KeyboardEvent }) => {
+ if (onKeyDown(event)) {
+ return true;
+ }
+
+ if (event.key === "Escape") {
+ onClose();
+ return true;
+ }
+ return false;
+ },
+ }));
+
+ const searchModelsReal = searchModels?.filter(
+ (model) =>
+ model !== "database" &&
+ model !== "action" &&
+ model !== "segment" &&
+ model !== "user",
+ );
+
+ const shouldHide = useMemo(() => {
+ const shouldDisableBasedOnDb = shouldDisableItemNotInDb(onlyDatabaseId);
+
+ return (item: MiniPickerItem | unknown): item is MiniPickerPickableItem => {
+ // @ts-expect-error - will fix when we align types with minipicker: UXW-2735
+ const dbId = item?.db_id ?? item?.database_id ?? item?.dbId ?? undefined;
+
+ return Boolean(
+ // @ts-expect-error - Will be fixed once we align types with minipicker: UXW-2735
+ shouldDisableBasedOnDb({ ...item, database_id: dbId }),
+ );
+ };
+ }, [onlyDatabaseId]);
+
+ // Because `Menu.Target` is set to just the mention decoration node,
+ // we need to have a custom "outside" definition to not close when clicking inside the editor.
+ useClickOutside(
+ () => {
+ if (closeOnClickOutside) {
+ onClose();
+ }
+ },
+ ["mousedown", "touchstart"],
+ [editor.view.dom, menuDropdownDom],
+ );
+
+ return (
+ <>
+ <MiniPicker
+ opened
+ searchQuery={query}
+ shouldShowLibrary
+ models={searchModelsReal ?? []}
+ closeOnClickOutside={false}
+ onChange={onSelectEntity}
+ onClose={onClose}
+ shouldHide={shouldHide}
+ onBrowseAll={() => {
+ setIsBrowsing(true);
+ }}
+ menuDropdownRef={menuDropdownRef}
+ menuDropdownProps={{
+ onFocus,
+ }}
+ className={styles.miniPicker}
+ >
+ <ExternalMenuTarget element={decorationNode} />
+ </MiniPicker>
+ {isBrowsing && (
+ <EntityPickerModal
+ title={t`Mention an item`}
+ value={
+ onlyDatabaseId
+ ? {
+ model: "database",
+ id: onlyDatabaseId,
+ }
+ : undefined
+ }
+ models={searchModelsReal ?? []}
+ options={{
+ hasDatabases: true,
+ hasRootCollection: true,
+ hasPersonalCollections: true,
+ hasSearch: true,
+ hasRecents: true,
+ hasLibrary: true,
+ hasConfirmButtons: false,
+ canCreateCollections: false,
+ canCreateDashboards: false,
+ }}
+ onChange={(item) => {
+ onSelectEntity(item);
+ onClose();
+ }}
+ onClose={() => {
+ setIsBrowsing(false);
+ }}
+ isDisabledItem={shouldDisableItemNotInDb(onlyDatabaseId)}
+ searchParams={
+ onlyDatabaseId !== undefined
+ ? {
+ table_db_id: onlyDatabaseId,
+ }
+ : undefined
+ }
+ searchQuery={query}
+ />
+ )}
+ </>
+ );
+});
+
+// In case of mentions, we want to have the editor focused while allowing navigation
+// inside the menu. We can't have two elements focused at the same time, so we fake
+// selections inside the menu.
+function useFakeKeyboardHandler(menuDropdownDom: Element | null) {
+ const getAllMenuItems = useCallback(() => {
+ if (!menuDropdownDom) {
+ throw Error("Menu element is not mounted.");
+ }
+
+ const items = Array.from(
+ menuDropdownDom.querySelectorAll('[role="menuitem"]'),
+ );
+
+ const selectedIndex = items.findIndex(
+ (item) => item.getAttribute("aria-selected") === "true",
+ );
+
+ if (selectedIndex === -1) {
+ return {
+ selectedItem: null,
+ selectedIndex: null,
+ items,
+ };
+ }
+
+ return {
+ selectedItem: items[selectedIndex],
+ selectedIndex: selectedIndex,
+ items,
+ };
+ }, [menuDropdownDom]);
+
+ const onKeyDown = useCallback(
+ (event: KeyboardEvent) => {
+ if (!menuDropdownDom) {
+ return false;
+ }
+
+ return match(event.key)
+ .returnType<boolean>()
+ .with("Home", "End", (key) => {
+ const { items, selectedItem } = getAllMenuItems();
+
+ if (selectedItem !== null) {
+ selectedItem.setAttribute("aria-selected", "false");
+ }
+
+ const nextIndex = key === "Home" ? 0 : items.length - 1;
+ const nextItem = items[nextIndex];
+ if (nextItem) {
+ nextItem.setAttribute("aria-selected", "true");
+ nextItem.scrollIntoView({ block: "nearest" });
+ }
+ return true;
+ })
+ .with("ArrowUp", "ArrowDown", (key) => {
+ const { items, selectedIndex, selectedItem } = getAllMenuItems();
+
+ if (selectedItem === null) {
+ items.at(0)?.setAttribute("aria-selected", "true");
+ return true;
+ }
+
+ let nextIndex =
+ key === "ArrowUp" ? selectedIndex - 1 : selectedIndex + 1;
+
+ if (nextIndex > items.length - 1) {
+ nextIndex = 0;
+ }
+ if (nextIndex < 0) {
+ nextIndex = items.length - 1;
+ }
+
+ const nextItem = items.at(nextIndex);
+ if (nextItem) {
+ selectedItem.removeAttribute("aria-selected");
+ nextItem.setAttribute("aria-selected", "true");
+ nextItem.scrollIntoView({ block: "nearest" });
+ }
+ return true;
+ })
+ .with("Enter", () => {
+ const { selectedItem } = getAllMenuItems();
+ if (selectedItem === null) {
+ return false;
+ }
+
+ if (selectedItem instanceof HTMLElement) {
+ selectedItem.click();
+ }
+ return true;
+ })
+ .otherwise(() => false);
+ },
+ [getAllMenuItems, menuDropdownDom],
+ );
+
+ // If the user explicitly focused in the menu, we want to switch to the default handlers instead of fake ones.
+ const onFocus = useCallback(() => {
+ if (!menuDropdownDom) {
+ return;
+ }
+
+ const { selectedItem } = getAllMenuItems();
+ if (selectedItem === null) {
+ return;
+ }
+ selectedItem.removeAttribute("aria-selected");
+ }, [getAllMenuItems, menuDropdownDom]);
+
+ return {
+ onKeyDown,
+ onFocus,
+ };
+}
+
+export const MetabotMentionSuggestionNew = MetabotMentionSuggestionComponent;
+
+export const createMetabotMentionSuggestionNew = (
+ outerProps: MetabotMentionSuggestionPropsBase,
+) => {
+ return forwardRef<BareSuggestionRendererRef, MetabotMentionSuggestionProps>(
+ function MentionSuggestionWrapper(props, ref) {
+ return (
+ <MetabotMentionSuggestionNew {...props} ref={ref} {...outerProps} />
+ );
+ },
+ );
+};
diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestionNew.unit.spec.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestionNew.unit.spec.tsx
new file mode 100644
index 00000000000..b89e32e4205
--- /dev/null
+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestionNew.unit.spec.tsx
@@ -0,0 +1,150 @@
+import userEvent from "@testing-library/user-event";
+import type { Editor } from "@tiptap/core";
+import { createRef } from "react";
+import { act } from "react-dom/test-utils";
+
+import { renderWithProviders, screen, waitFor } from "__support__/ui";
+import type { EntityPickerModalProps } from "metabase/common/components/Pickers";
+import type { OmniPickerItem } from "metabase/common/components/Pickers/EntityPicker/types";
+import type { MiniPickerProps } from "metabase/common/components/Pickers/MiniPicker/components/MiniPicker/MiniPicker";
+import type { MiniPickerPickableItem } from "metabase/common/components/Pickers/MiniPicker/types";
+import type { BareSuggestionRendererRef } from "metabase/rich_text_editing/tiptap/extensions/suggestionRenderer";
+
+import type { MetabotMentionSuggestionProps } from "./MetabotSuggestionNew";
+import { MetabotMentionSuggestionNew } from "./MetabotSuggestionNew";
+
+jest.mock("metabase/common/components/Pickers", () => {
+ return {
+ MiniPicker: (props: MiniPickerProps) => {
+ const miniItem: MiniPickerPickableItem = {
+ id: 1,
+ model: "card",
+ name: "Mini card",
+ };
+
+ return (
+ <div data-testid="mini-picker">
+ <button onClick={() => props.onChange(miniItem)}>mini-select</button>
+ <button onClick={() => props.onBrowseAll?.()}>browse-all</button>
+ {props.children}
+ </div>
+ );
+ },
+ EntityPickerModal: (props: EntityPickerModalProps) => {
+ const modalItem: OmniPickerItem = {
+ id: 2,
+ model: "dashboard",
+ name: "Modal dashboard",
+ };
+
+ return (
+ <div data-testid="entity-picker-modal">
+ <button onClick={() => props.onChange(modalItem)}>
+ modal-select
+ </button>
+ <button onClick={props.onClose}>modal-close</button>
+ </div>
+ );
+ },
+ };
+});
+
+const setup = (props: Partial<MetabotMentionSuggestionProps> = {}) => {
+ const command = jest.fn();
+ const onClose = jest.fn();
+ const ref = createRef<BareSuggestionRendererRef>();
+ const focusMock = jest.fn();
+ const editor = {
+ commands: {
+ focus: focusMock,
+ },
+ view: {
+ dom: document.createElement("div"),
+ },
+ } as unknown as Editor;
+
+ const defaultProps: MetabotMentionSuggestionProps = {
+ items: [],
+ command,
+ editor,
+ range: { from: 1, to: 1 },
+ query: "ord",
+ text: "@ord",
+ onClose,
+ decorationNode: null,
+ clientRect: null,
+ ...props,
+ };
+
+ renderWithProviders(
+ <MetabotMentionSuggestionNew {...defaultProps} ref={ref} />,
+ );
+
+ return { command, onClose, editor, ref, focusMock };
+};
+
+describe("MetabotMentionSuggestionNew", () => {
+ it("selecting mini picker item calls command with mention payload", async () => {
+ const { command } = setup();
+
+ await userEvent.click(screen.getByRole("button", { name: "mini-select" }));
+
+ expect(command).toHaveBeenCalledWith({
+ id: 1,
+ model: "card",
+ label: "Mini card",
+ });
+ });
+
+ it("selecting browse-all modal item calls command and closes suggestion", async () => {
+ const { command, onClose } = setup();
+
+ await userEvent.click(screen.getByRole("button", { name: "browse-all" }));
+ expect(
+ await screen.findByTestId("entity-picker-modal"),
+ ).toBeInTheDocument();
+ await userEvent.click(screen.getByRole("button", { name: "modal-select" }));
+
+ expect(command).toHaveBeenCalledWith({
+ id: 2,
+ model: "dashboard",
+ label: "Modal dashboard",
+ });
+ expect(onClose).toHaveBeenCalled();
+ });
+
+ it("closing browse-all modal hides EntityPickerModal but not the mini picker", async () => {
+ setup();
+
+ await userEvent.click(screen.getByRole("button", { name: "browse-all" }));
+ expect(
+ await screen.findByTestId("entity-picker-modal"),
+ ).toBeInTheDocument();
+
+ await userEvent.click(screen.getByRole("button", { name: "modal-close" }));
+
+ await waitFor(() => {
+ expect(
+ screen.queryByTestId("entity-picker-modal"),
+ ).not.toBeInTheDocument();
+ });
+
+ expect(
+ await screen.findByRole("button", { name: "mini-select" }),
+ ).toBeInTheDocument();
+ });
+
+ it("pressing Escape closes suggestion when focus is on field", () => {
+ const { onClose, ref } = setup();
+ let handled: boolean | undefined;
+
+ act(() => {
+ handled = ref.current?.onKeyDown({
+ event: new KeyboardEvent("keydown", { key: "Escape" }),
+ });
+ });
+
+ expect(handled).toBe(true);
+ expect(onClose).toHaveBeenCalled();
+ });
+});
diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/ExternalMenuTarget.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/ExternalMenuTarget.tsx
new file mode 100644
index 00000000000..a05cdb79149
--- /dev/null
+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/ExternalMenuTarget.tsx
@@ -0,0 +1,20 @@
+import { forwardRef, useImperativeHandle } from "react";
+
+type ExternalMenuTargetProps = {
+ element: Element | null;
+};
+
+/**
+ * Mantine's Menu.Target expects a React element it can attach a ref to.
+ * For TipTap suggestions we often already have a real DOM node (`decorationNode`).
+ *
+ * This component bridges those worlds by forwarding the ref to an existing DOM element.
+ */
+export const ExternalMenuTarget = forwardRef<
+ Element | null,
+ ExternalMenuTargetProps
+>(function ExternalMenuTarget({ element }, ref) {
+ useImperativeHandle(ref, () => element, [element]);
+
+ return null;
+});
diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/suggestionRenderer.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/suggestionRenderer.tsx
index 864791c81d2..545ee2b65a7 100644
--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/suggestionRenderer.tsx
+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/suggestionRenderer.tsx
@@ -208,3 +208,75 @@ export const createSuggestionRenderer = <I = unknown, TSelected = unknown>(
};
};
};
+
+export interface BareSuggestionRendererProps<I = unknown, TSelected = unknown>
+ extends SuggestionProps<I, TSelected> {
+ onClose: () => void;
+}
+
+export interface BareSuggestionRendererRef {
+ onKeyDown: (props: { event: KeyboardEvent }) => boolean;
+}
+
+/**
+ * Mount a suggestion component without positioning/styling a container.
+ *
+ * Useful when the suggestion UI uses its own overlay component (e.g. Mantine Menu)
+ * and anchors itself to `props.decorationNode`.
+ */
+export const createBareSuggestionRenderer = <I = unknown, TSelected = unknown>(
+ SuggestionComponent: React.ComponentType<
+ BareSuggestionRendererProps<I, TSelected>
+ >,
+) => {
+ return () => {
+ let component: ReactRenderer | undefined;
+
+ const destroy = () => {
+ if (
+ component?.element instanceof HTMLElement &&
+ document.body.contains(component.element)
+ ) {
+ document.body.removeChild(component.element);
+ }
+ component?.destroy();
+ component = undefined;
+ };
+
+ return {
+ onStart: (props: SuggestionProps<I, TSelected>) => {
+ component = new ReactRenderer(SuggestionComponent, {
+ props: {
+ ...props,
+ onClose: destroy,
+ },
+ editor: props.editor,
+ });
+ },
+
+ onUpdate(props: SuggestionProps<I, TSelected>) {
+ component?.updateProps({
+ ...props,
+ onClose: destroy,
+ });
+ },
+
+ onKeyDown(props: SuggestionKeyDownProps) {
+ const ref = component?.ref;
+ if (
+ ref &&
+ typeof ref === "object" &&
+ "onKeyDown" in ref &&
+ typeof ref.onKeyDown === "function"
+ ) {
+ return ref.onKeyDown(props);
+ }
+ return false;
+ },
+
+ onExit() {
+ destroy();
+ },
+ };
+ };
+};
diff --git a/frontend/src/metabase/ui/components/overlays/Menu/Menu.module.css b/frontend/src/metabase/ui/components/overlays/Menu/Menu.module.css
index df3053a06fb..3df1491034f 100644
--- a/frontend/src/metabase/ui/components/overlays/Menu/Menu.module.css
+++ b/frontend/src/metabase/ui/components/overlays/Menu/Menu.module.css
@@ -21,7 +21,8 @@
background-color: var(--mb-color-background-hover);
}
- &:focus {
+ &:focus,
+ &[aria-selected="true"] {
outline: none;
background-color: var(--mb-color-background-hover);
border: none;
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 b8d18752d58..b83d890d77f 100644
--- a/frontend/src/metabase/ui/components/overlays/Menu/MenuDropdown/MenuDropdown.tsx
+++ b/frontend/src/metabase/ui/components/overlays/Menu/MenuDropdown/MenuDropdown.tsx
@@ -1,22 +1,25 @@
import type { MenuDropdownProps } from "@mantine/core";
import { Menu } from "@mantine/core";
-import type { ReactNode } from "react";
-import { useEffect } from "react";
+import type { ReactNode, Ref } from "react";
+import { forwardRef, useEffect } from "react";
import { useSequencedContentCloseHandler } from "metabase/common/hooks/use-sequenced-content-close-handler";
import { PreventEagerPortal } from "metabase/ui";
// hack to prevent parent TippyPopover from closing when selecting a Menu.Item
// remove when TippyPopover is no longer used
-export function MenuDropdown({ children, ...props }: MenuDropdownProps) {
+export const MenuDropdown = forwardRef(function MenuDropdown(
+ { children, ...props }: MenuDropdownProps,
+ ref: Ref<HTMLDivElement>,
+) {
return (
<PreventEagerPortal {...props}>
- <Menu.Dropdown {...props} data-element-id="mantine-popover">
+ <Menu.Dropdown {...props} data-element-id="mantine-popover" ref={ref}>
<MenuDropdownContent>{children}</MenuDropdownContent>
</Menu.Dropdown>
</PreventEagerPortal>
);
-}
+});
interface MenuDropdownContentProps {
children?: ReactNode;
diff --git a/frontend/src/metabase/ui/index.ts b/frontend/src/metabase/ui/index.ts
index de179c5018d..de6ad4ecfc4 100644
--- a/frontend/src/metabase/ui/index.ts
+++ b/frontend/src/metabase/ui/index.ts
@@ -1,5 +1,6 @@
export { rem, useCombobox, useMantineTheme, useMatches } from "@mantine/core";
export type {
+ MenuDropdownProps,
ComboboxStore,
FloatingPosition,
MantineSize,