Skip to content

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

Allow opening dashboard filters using keyboard (#62716)

Romeo Van Snickda1637a88294
diff --git a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_filters_Dark_Theme_Date_Filter_Quarter_Year.png b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_filters_Dark_Theme_Date_Filter_Quarter_Year.png
index 9553ab959f4..505757bf0c9 100644
Binary files a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_filters_Dark_Theme_Date_Filter_Quarter_Year.png and b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_filters_Dark_Theme_Date_Filter_Quarter_Year.png differ
diff --git a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_filters_Light_Theme_Date_Filter_Quarter_Year.png b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_filters_Light_Theme_Date_Filter_Quarter_Year.png
index 2c8531a9a42..2692c09d752 100644
Binary files a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_filters_Light_Theme_Date_Filter_Quarter_Year.png and b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_filters_Light_Theme_Date_Filter_Quarter_Year.png differ
diff --git a/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.js b/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.js
index 6e02c00ece3..de13e85b109 100644
--- a/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.js
+++ b/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.js
@@ -2079,3 +2079,78 @@ describe("issue 62170", () => {
cy.get("@dashboardLoad.all").should("have.length", 1);
});
});
+
+describe("issue 52674", () => {
+ beforeEach(() => {
+ H.restore();
+ cy.signInAsAdmin();
+ });
+
+ it("should be possible to open a parameter widget using the keyboard shortcut (metabase#52674)", () => {
+ H.createDashboardWithQuestions({
+ questions: [
+ {
+ query: {
+ "source-table": ORDERS_ID,
+ },
+ },
+ ],
+ dashboardDetails: {
+ parameters: [
+ createMockParameter({
+ id: "param-1",
+ name: "Number",
+ slug: "number",
+ type: "number/between",
+ }),
+ ],
+ },
+ }).then(({ dashboard }) => {
+ cy.request("GET", `/api/dashboard/${dashboard.id}`).then(
+ ({ body: dashboard }) => {
+ const [dashcard] = dashboard.dashcards;
+ const [parameter] = dashboard.parameters;
+ cy.request("PUT", `/api/dashboard/${dashboard.id}`, {
+ dashcards: [
+ {
+ ...dashcard,
+ parameter_mappings: [
+ {
+ card_id: dashcard.card_id,
+ parameter_id: parameter.id,
+ target: [
+ "dimension",
+ [
+ "field",
+ ORDERS.TOTAL,
+ {
+ "base-type": "type/Number",
+ },
+ ],
+ ],
+ },
+ ],
+ },
+ ],
+ }).then(() => {
+ cy.wrap(dashboard.id).as("dashboardId");
+ });
+ },
+ );
+ });
+ H.visitDashboard("@dashboardId");
+
+ cy.log("Opening with Enter should work");
+ H.main().button("Number").focus();
+ cy.realPress("Enter");
+ H.popover().should("be.visible");
+
+ cy.log("Close the popover");
+ H.main().button("Number").click();
+
+ cy.log("Opening with Space should work");
+ H.main().button("Number").focus();
+ cy.realPress("Space");
+ H.popover().should("be.visible");
+ });
+});
diff --git a/frontend/src/metabase/common/components/Sortable/Sortable.tsx b/frontend/src/metabase/common/components/Sortable/Sortable.tsx
index ba434861851..9be9d69b9ac 100644
--- a/frontend/src/metabase/common/components/Sortable/Sortable.tsx
+++ b/frontend/src/metabase/common/components/Sortable/Sortable.tsx
@@ -79,7 +79,7 @@ export function Sortable({
}}
data-is-dragging={isDragging}
ref={setNodeRef}
- {...attributes}
+ {...(disabled ? {} : attributes)}
{...(!childrenAsFunction && listeners)}
role={role}
>
diff --git a/frontend/src/metabase/parameters/components/ParameterValueWidget.tsx b/frontend/src/metabase/parameters/components/ParameterValueWidget.tsx
index 23153decfaf..d4ea04eeb5c 100644
--- a/frontend/src/metabase/parameters/components/ParameterValueWidget.tsx
+++ b/frontend/src/metabase/parameters/components/ParameterValueWidget.tsx
@@ -273,6 +273,7 @@ export const ParameterValueWidget = ({
className={className}
ariaLabel={placeholder}
mimicMantine={mimicMantine}
+ hasPopover
>
{typeIcon}
{prefix && <div className={S.Prefix}>{prefix}</div>}
diff --git a/frontend/src/metabase/parameters/components/ParameterValueWidgetTrigger.tsx b/frontend/src/metabase/parameters/components/ParameterValueWidgetTrigger.tsx
index d54e0e259bd..1c9550f1916 100644
--- a/frontend/src/metabase/parameters/components/ParameterValueWidgetTrigger.tsx
+++ b/frontend/src/metabase/parameters/components/ParameterValueWidgetTrigger.tsx
@@ -1,7 +1,7 @@
import cx from "classnames";
import { type ReactNode, type Ref, forwardRef } from "react";
-import { Flex } from "metabase/ui";
+import { Box, Flex, UnstyledButton } from "metabase/ui";
import S from "./ParameterValueWidget.module.css";
@@ -16,15 +16,32 @@ function ParameterValueWidgetTriggerInner(
ariaLabel,
className,
mimicMantine = false,
+ hasPopover = false,
}: {
children: ReactNode;
hasValue: boolean;
ariaLabel?: string;
className?: string;
mimicMantine?: boolean;
+ hasPopover?: boolean;
},
- ref: Ref<HTMLDivElement>,
+ ref: Ref<HTMLButtonElement | HTMLButtonElement>,
) {
+ const attributes = hasPopover
+ ? {
+ // HACK: This is a hack to make typescript think we're rendering a button.
+ // UnstyledButton's styles are widened somewhere down the stack so that they
+ // are not compatible with Ref<HTMLButtonElement> and we need to cast it to "button"
+ // to sidestep this issue.
+ component: UnstyledButton as unknown as "button",
+ ref: ref as Ref<HTMLButtonElement>,
+ type: "button" as const,
+ }
+ : {
+ component: "div" as const,
+ ref: ref as Ref<HTMLDivElement>,
+ };
+
if (mimicMantine) {
return (
<Flex
@@ -35,7 +52,7 @@ function ParameterValueWidgetTriggerInner(
[S.hasValue]: hasValue,
})}
aria-label={ariaLabel}
- ref={ref}
+ {...attributes}
>
{children}
</Flex>
@@ -43,15 +60,14 @@ function ParameterValueWidgetTriggerInner(
}
return (
- <div
- ref={ref}
+ <Box
className={cx(S.parameter, className, {
[S.selected]: hasValue,
})}
- role="button"
aria-label={ariaLabel}
+ {...attributes}
>
{children}
- </div>
+ </Box>
);
}