The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Subtract scrollbar with from pivot table header when apropriate (#71654)
Nick Fitzpatrick6af2a17af7d2
diff --git a/frontend/src/metabase/visualizations/visualizations/PivotTable/PivotTable.tsx b/frontend/src/metabase/visualizations/visualizations/PivotTable/PivotTable.tsxindex cd9ea9e4e89..b558cc2ca5b 100644--- a/frontend/src/metabase/visualizations/visualizations/PivotTable/PivotTable.tsx+++ b/frontend/src/metabase/visualizations/visualizations/PivotTable/PivotTable.tsx@@ -360,7 +360,10 @@ const PivotTableInner = forwardRef<HTMLDivElement, VisualizationProps>(const topHeaderHeight = topHeaderRows * CELL_HEIGHT;const bodyHeight = height - topHeaderHeight;- const topHeaderWidth = viewPortWidth - leftHeaderWidth;+ const verticalScrollBarSize =+ rowCount * CELL_HEIGHT > bodyHeight ? getScrollBarSize() : 0;+ const topHeaderWidth =+ viewPortWidth - leftHeaderWidth - verticalScrollBarSize;function getCellClickHandler(clicked: PivotTableClicked) {if (!clicked) {@@ -464,6 +467,7 @@ const PivotTableInner = forwardRef<HTMLDivElement, VisualizationProps>(</PivotTableTopLeftCellsContainer>{/* top header */}<Collection+ aria-label="pivot-table-top-header"style={{ minWidth: `${topHeaderWidth}px` }}ref={topHeaderRef}className={CS.scrollHideAll}diff --git a/frontend/src/metabase/visualizations/visualizations/PivotTable/PivotTable.unit.spec.tsx b/frontend/src/metabase/visualizations/visualizations/PivotTable/PivotTable.unit.spec.tsxindex bbfbb68b09d..8903922d710 100644--- a/frontend/src/metabase/visualizations/visualizations/PivotTable/PivotTable.unit.spec.tsx+++ b/frontend/src/metabase/visualizations/visualizations/PivotTable/PivotTable.unit.spec.tsx@@ -6,6 +6,7 @@ import { useState } from "react";import { createMockMetadata } from "__support__/metadata";import { renderWithProviders } from "__support__/ui";+import * as domUtils from "metabase/lib/dom";import { QuestionChartSettings } from "metabase/visualizations/components/ChartSettings";import registerVisualizations from "metabase/visualizations/register";import Question from "metabase-lib/v1/Question";@@ -50,7 +51,7 @@ const TEST_CASES = [function setupPivotTable(options?: ComponentProps<typeof PivotTableTestWrapper>,) {- renderWithProviders(<PivotTableTestWrapper {...options} />);+ return renderWithProviders(<PivotTableTestWrapper {...options} />);}function setupPivotSettings() {@@ -267,6 +268,32 @@ describe("Visualizations > PivotTable > PivotTable", () => {});});});++ describe("scrollbar alignment", () => {+ it("should reduce top header width by scrollbar size when body has vertical scrollbar", () => {+ const scrollBarSize = 15;+ jest.spyOn(domUtils, "getScrollBarSize").mockReturnValue(scrollBarSize);++ // Use a small height to force vertical scrolling (4 rows * 30px = 120px body content)+ const { rerender } = setupPivotTable({ height: 100 });++ const getTopHeaderWidth = () => {+ const topHeader = screen.getByLabelText("pivot-table-top-header");+ return parseInt(topHeader.style.minWidth);+ };++ const widthWithScrollbar = getTopHeaderWidth();++ // Re-render with enough height that no vertical scrollbar is needed+ rerender(<PivotTableTestWrapper height={500} />);++ const widthWithoutScrollbar = getTopHeaderWidth();++ expect(widthWithoutScrollbar - widthWithScrollbar).toBe(scrollBarSize);++ jest.restoreAllMocks();+ });+ });});describe("Visualizations > PivotTable > Chart Settings", () => {