Skip to content

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

Enable keyboard navigation in dashcard download data popover (#70541) (#70965)

Anderson3969de09bb60
diff --git a/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.tsx b/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.tsx
index 82a9b77169f..c0c421d08f8 100644
--- a/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.tsx
+++ b/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.tsx
@@ -127,32 +127,22 @@ export const DashCardMenu = ({
canEdit={canEdit}
/>
{openUnderlyingQuestionItems && (
- <Menu trigger="click-hover" shadow="md" position="right" width={200}>
- <Menu.Target>
- <Menu.Item
+ <Menu.Sub position="right" shadow="md">
+ <Menu.Sub.Target>
+ <Menu.Sub.Item
fw="bold"
- styles={{
- // styles needed to override the hover styles
- // as hovering is bugged for submenus
- // this'll be much better in v8
- item: {
- backgroundColor: "transparent",
- color: "var(--mb-color-text-primary)",
- },
- itemSection: {
- color: "var(--mb-color-text-primary)",
- },
- }}
leftSection={<Icon name="external" aria-hidden />}
- rightSection={<Icon name="chevronright" aria-hidden />}
>
{t`View question(s)`}
- </Menu.Item>
- </Menu.Target>
- <Menu.Dropdown data-testid="dashcard-menu-open-underlying-question">
+ </Menu.Sub.Item>
+ </Menu.Sub.Target>
+ <Menu.Sub.Dropdown
+ data-testid="dashcard-menu-open-underlying-question"
+ style={{ maxWidth: "15rem" }}
+ >
{openUnderlyingQuestionItems}
- </Menu.Dropdown>
- </Menu>
+ </Menu.Sub.Dropdown>
+ </Menu.Sub>
)}
</>
);
diff --git a/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.unit.spec.tsx b/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.unit.spec.tsx
index c30e52ff2c3..d830cad4ddf 100644
--- a/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.unit.spec.tsx
+++ b/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.unit.spec.tsx
@@ -283,4 +283,29 @@ describe("DashCardMenu", () => {
expect(await screen.findByText("Download results")).toBeInTheDocument();
expect(screen.queryByText("Edit visualization")).not.toBeInTheDocument();
});
+
+ it("should support keyboard navigation in download popover", async () => {
+ setup();
+
+ await userEvent.click(getIcon("ellipsis"));
+ await userEvent.click(await screen.findByText("Download results"));
+
+ // Verify format options are keyboard accessible (as radio buttons)
+ const csvButton = screen.getByRole("radio", { name: ".csv" });
+ expect(csvButton).toBeInTheDocument();
+
+ // Verify that format options can receive focus
+ csvButton.focus();
+ expect(csvButton).toHaveFocus();
+
+ // Test navigation between format options using arrow keys
+ await userEvent.keyboard("{ArrowRight}");
+ // After arrow right, a format option should still have focus (exact option may vary)
+ const xlsxButton = screen.getByRole("radio", { name: ".png" });
+ expect(xlsxButton).toHaveFocus();
+
+ // Esc should close the popover
+ await userEvent.keyboard("{Esc}");
+ expect(screen.queryByText("Download results")).not.toBeInTheDocument();
+ });
});
diff --git a/frontend/src/metabase/dashboard/components/DashCard/PublicOrEmbeddedDashCardMenu.tsx b/frontend/src/metabase/dashboard/components/DashCard/PublicOrEmbeddedDashCardMenu.tsx
index 3b328a817ab..ad9b1210087 100644
--- a/frontend/src/metabase/dashboard/components/DashCard/PublicOrEmbeddedDashCardMenu.tsx
+++ b/frontend/src/metabase/dashboard/components/DashCard/PublicOrEmbeddedDashCardMenu.tsx
@@ -57,7 +57,14 @@ export const PublicOrEmbeddedDashCardMenu = ({
});
return (
- <Menu offset={4} position="bottom-end" opened={isOpen} onClose={close}>
+ <Menu
+ closeOnEscape
+ offset={4}
+ onClose={close}
+ opened={isOpen}
+ position="bottom-end"
+ trapFocus
+ >
<Menu.Target>
<ActionIcon
size="xs"
diff --git a/frontend/src/metabase/query_builder/components/QuestionDownloadWidget/QuestionDownloadWidget.tsx b/frontend/src/metabase/query_builder/components/QuestionDownloadWidget/QuestionDownloadWidget.tsx
index 6b7e8b0ec42..1204638272a 100644
--- a/frontend/src/metabase/query_builder/components/QuestionDownloadWidget/QuestionDownloadWidget.tsx
+++ b/frontend/src/metabase/query_builder/components/QuestionDownloadWidget/QuestionDownloadWidget.tsx
@@ -16,6 +16,7 @@ import {
Box,
Button,
Flex,
+ FocusTrap,
Icon,
Stack,
type StackProps,
@@ -153,78 +154,80 @@ export const QuestionDownloadWidget = ({
showMetabaseLinks;
return (
- <Stack {...stackProps} w={336} p="0.75rem" gap="lg">
- <Title order={5}>{t`Download data`}</Title>
- <ExportSettingsWidget
- selectedFormat={format}
- formats={formats}
- isFormattingEnabled={isFormatted}
- isPivotingEnabled={isPivoted}
- canConfigureFormatting={canConfigureFormatting(format)}
- canConfigurePivoting={canConfigurePivoting}
- onChangeFormat={handleFormatChange}
- onToggleFormatting={() => setIsFormatted((prev) => !prev)}
- onTogglePivoting={() => setIsPivoted((prev) => !prev)}
- />
- {showPivotXlsxExportHint && (
- <Flex
- p="md"
- bg="background-secondary"
- align="center"
- justify="space-between"
- className={CS.rounded}
- >
- <Text fz="12px" lh="16px" c="text-secondary">
- {t`Trying to pivot this data in Excel? You should download the raw data instead.`}{" "}
- <Link
- target="_new"
- to={pivotExcelExportsDocsLink}
- style={{ color: "var(--mb-color-brand)" }}
- >
- {t`Read the docs`}
- </Link>
- </Text>
- <Button
- aria-label={t`Close hint`}
- pl={8}
- pr={0}
- variant="subtle"
- size="compact-md"
- style={{ flexShrink: 0 }}
+ <FocusTrap>
+ <Stack {...stackProps} w={336} p="0.75rem" gap="lg">
+ <Title order={5}>{t`Download data`}</Title>
+ <ExportSettingsWidget
+ selectedFormat={format}
+ formats={formats}
+ isFormattingEnabled={isFormatted}
+ isPivotingEnabled={isPivoted}
+ canConfigureFormatting={canConfigureFormatting(format)}
+ canConfigurePivoting={canConfigurePivoting}
+ onChangeFormat={handleFormatChange}
+ onToggleFormatting={() => setIsFormatted((prev) => !prev)}
+ onTogglePivoting={() => setIsPivoted((prev) => !prev)}
+ />
+ {showPivotXlsxExportHint && (
+ <Flex
+ p="md"
+ bg="background-secondary"
+ align="center"
+ justify="space-between"
+ className={CS.rounded}
>
- <Icon
- name="close"
- c="text-secondary"
- tooltip={t`Don't show me this again.`}
- onClick={() => setDismissedExcelPivotExportsBanner(true)}
- />
- </Button>
- </Flex>
- )}
- {hasTruncatedResults && (
- <Box>
- <Text
- size="sm"
- c="text-secondary"
- mb="1rem"
- >{t`Your answer has a large number of rows so it could take a while to download.`}</Text>
-
- {format === "xlsx" && (
- <Text size="sm" c="text-secondary">
- {limitedDownloadSizeText}
+ <Text fz="12px" lh="16px" c="text-secondary">
+ {t`Trying to pivot this data in Excel? You should download the raw data instead.`}{" "}
+ <Link
+ target="_new"
+ to={pivotExcelExportsDocsLink}
+ style={{ color: "var(--mb-color-brand)" }}
+ >
+ {t`Read the docs`}
+ </Link>
</Text>
- )}
- </Box>
- )}
- <Button
- data-testid="download-results-button"
- mt="auto"
- ml="auto"
- variant="filled"
- loading={loading}
- onClick={handleDownload}
- disabled={disabled}
- >{t`Download`}</Button>
- </Stack>
+ <Button
+ aria-label={t`Close hint`}
+ pl={8}
+ pr={0}
+ variant="subtle"
+ size="compact-md"
+ style={{ flexShrink: 0 }}
+ >
+ <Icon
+ name="close"
+ c="text-secondary"
+ tooltip={t`Don't show me this again.`}
+ onClick={() => setDismissedExcelPivotExportsBanner(true)}
+ />
+ </Button>
+ </Flex>
+ )}
+ {hasTruncatedResults && (
+ <Box>
+ <Text
+ size="sm"
+ c="text-secondary"
+ mb="1rem"
+ >{t`Your answer has a large number of rows so it could take a while to download.`}</Text>
+
+ {format === "xlsx" && (
+ <Text size="sm" c="text-secondary">
+ {limitedDownloadSizeText}
+ </Text>
+ )}
+ </Box>
+ )}
+ <Button
+ data-testid="download-results-button"
+ mt="auto"
+ ml="auto"
+ variant="filled"
+ loading={loading}
+ onClick={handleDownload}
+ disabled={disabled}
+ >{t`Download`}</Button>
+ </Stack>
+ </FocusTrap>
);
};