Skip to content

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

Fix: UXW-511 Up/down keys not functioning in a Document that contains detail views (#62353)

Brad Andersond1b83f9b0207
diff --git a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.tsx b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.tsx
index 16cd92d0f14..633abdfd1ac 100644
--- a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.tsx
+++ b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.tsx
@@ -164,7 +164,7 @@ export function ObjectDetailView({
});
useEffect(() => {
- if (hasNotFoundError) {
+ if (hasNotFoundError || !showControls) {
return;
}
@@ -185,6 +185,7 @@ export function ObjectDetailView({
return () => window.removeEventListener("keydown", onKeyDown, true);
}, [
hasNotFoundError,
+ showControls,
viewPreviousObjectDetail,
viewNextObjectDetail,
closeObjectDetail,
diff --git a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.unit.spec.tsx b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.unit.spec.tsx
index b2545eaaa97..ed894a9b40d 100644
--- a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.unit.spec.tsx
+++ b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.unit.spec.tsx
@@ -513,6 +513,44 @@ describe("ObjectDetailView", () => {
"Are you sure you want to delete this row?",
);
});
+
+ describe("keyboard bindings", () => {
+ it("should be added when showControls is true", async () => {
+ const mockViewPreviousObjectDetail = jest.fn();
+ const mockViewNextObjectDetail = jest.fn();
+
+ setup({
+ question: mockQuestion,
+ showControls: true,
+ viewPreviousObjectDetail: mockViewPreviousObjectDetail,
+ viewNextObjectDetail: mockViewNextObjectDetail,
+ });
+
+ await userEvent.keyboard("{ArrowUp}");
+ expect(mockViewPreviousObjectDetail).toHaveBeenCalledTimes(1);
+
+ await userEvent.keyboard("{ArrowDown}");
+ expect(mockViewNextObjectDetail).toHaveBeenCalledTimes(1);
+ });
+
+ it("should not be added when showControls is false", async () => {
+ const mockViewPreviousObjectDetail = jest.fn();
+ const mockViewNextObjectDetail = jest.fn();
+
+ setup({
+ question: mockQuestion,
+ showControls: false,
+ viewPreviousObjectDetail: mockViewPreviousObjectDetail,
+ viewNextObjectDetail: mockViewNextObjectDetail,
+ });
+
+ await userEvent.keyboard("{ArrowUp}");
+ expect(mockViewPreviousObjectDetail).not.toHaveBeenCalled();
+
+ await userEvent.keyboard("{ArrowDown}");
+ expect(mockViewNextObjectDetail).not.toHaveBeenCalled();
+ });
+ });
});
async function findActionInActionMenu({ name }: Pick<WritebackAction, "name">) {