Skip to content

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

Fix doubled border under dashboard tabs (#83295)

Maz Ameli37524727371b
diff --git a/frontend/src/metabase/dashboard/components/Dashboard/Dashboard.tsx b/frontend/src/metabase/dashboard/components/Dashboard/Dashboard.tsx
index 4cc470b5687..64d05d61c8f 100644
--- a/frontend/src/metabase/dashboard/components/Dashboard/Dashboard.tsx
+++ b/frontend/src/metabase/dashboard/components/Dashboard/Dashboard.tsx
@@ -91,7 +91,9 @@ const DashboardDefaultView = ({ className }: { className?: string }) => {
{
[S.isEmbeddingSdk]: isEmbeddingSdk(),
[S.isFullscreen]: isFullscreen,
- [S.noBorder]: !hasTabs && !isHeaderVisible,
+ // The tab row draws its own full-width bottom border, so drop the
+ // header container's border when tabs are shown to avoid a doubled line.
+ [S.noBorder]: hasTabs || isEditing || !isHeaderVisible,
},
)}
data-element-id="dashboard-header-container"
diff --git a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderView.module.css b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderView.module.css
index 6f891cda5aa..6f19cbf1cd7 100644
--- a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderView.module.css
+++ b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderView.module.css
@@ -17,6 +17,8 @@
.DashboardHeader {
container-type: inline-size;
container-name: dashboard-header;
+ /* Clips the tab row's full-bleed border to the header's edges */
+ overflow-x: clip;
}
.HeaderContainer {
diff --git a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderView.tsx b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderView.tsx
index 5db05dbcdec..59c51f2fa9e 100644
--- a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderView.tsx
+++ b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderView.tsx
@@ -185,7 +185,7 @@ export function DashboardHeaderView({
data-testid="fixed-width-dashboard-tabs"
isFixedWidth={dashboard?.width === "fixed"}
>
- <DashboardTabs />
+ <DashboardTabs hasFullBleedBorder />
</FixedWidthContainer>
</FullWidthContainer>
</div>
diff --git a/frontend/src/metabase/dashboard/components/DashboardTabs/DashboardTabs.module.css b/frontend/src/metabase/dashboard/components/DashboardTabs/DashboardTabs.module.css
index 72e5d560eec..8e0ba46d7dc 100644
--- a/frontend/src/metabase/dashboard/components/DashboardTabs/DashboardTabs.module.css
+++ b/frontend/src/metabase/dashboard/components/DashboardTabs/DashboardTabs.module.css
@@ -9,6 +9,19 @@
bottom: 0;
width: 100%;
}
+
+ /* The border stands in for the dashboard header's own border here, so keep it
+ inside the header (where the sticky filter bar can't cover it) and let an
+ ancestor with overflow-x: clip trim it to the header's edges. */
+ &.fullBleedBorder {
+ margin-bottom: 0;
+
+ &:before {
+ left: -100vw;
+ right: -100vw;
+ width: auto;
+ }
+ }
}
.createTabButton {
diff --git a/frontend/src/metabase/dashboard/components/DashboardTabs/DashboardTabs.tsx b/frontend/src/metabase/dashboard/components/DashboardTabs/DashboardTabs.tsx
index 8afb5c27a1e..8161b116656 100644
--- a/frontend/src/metabase/dashboard/components/DashboardTabs/DashboardTabs.tsx
+++ b/frontend/src/metabase/dashboard/components/DashboardTabs/DashboardTabs.tsx
@@ -1,3 +1,4 @@
+import cx from "classnames";
import { t } from "ttag";
import { uniq } from "underscore";
@@ -17,7 +18,17 @@ import { isVirtualDashCard } from "metabase/utils/dashboard";
import S from "./DashboardTabs.module.css";
import { useDashboardTabs } from "./use-dashboard-tabs";
-export function DashboardTabs() {
+interface DashboardTabsProps {
+ /**
+ * Extend the bottom border to the edges of the nearest ancestor that clips
+ * horizontal overflow, so it can stand in for the dashboard header's border.
+ */
+ hasFullBleedBorder?: boolean;
+}
+
+export function DashboardTabs({
+ hasFullBleedBorder = false,
+}: DashboardTabsProps = {}) {
const { isEditing = false, dashboard } = useDashboardContext();
const { modalContent, show } = useConfirmation();
@@ -117,7 +128,14 @@ export function DashboardTabs() {
}
return (
- <Flex align="start" gap="xl" w="100%" className={S.dashboardTabs}>
+ <Flex
+ align="start"
+ gap="xl"
+ w="100%"
+ className={cx(S.dashboardTabs, {
+ [S.fullBleedBorder]: hasFullBleedBorder,
+ })}
+ >
<TabRow<SelectedTabId>
value={selectedTabId}
onChange={selectTab}
diff --git a/frontend/src/metabase/dashboard/hooks/use-is-parameter-panel-sticky.ts b/frontend/src/metabase/dashboard/hooks/use-is-parameter-panel-sticky.ts
index 7dccd27ea83..96c874f1877 100644
--- a/frontend/src/metabase/dashboard/hooks/use-is-parameter-panel-sticky.ts
+++ b/frontend/src/metabase/dashboard/hooks/use-is-parameter-panel-sticky.ts
@@ -37,11 +37,13 @@ export function useIsParameterPanelSticky({
threshold: 0, // We only need to know when sentinel is out of view
};
- const observer = new IntersectionObserver(([entry]) => {
- setIsStickyStateChanging(true);
+ const observer = new IntersectionObserver((entries) => {
+ // Entries queue up oldest-first (e.g. during a window resize), so only the
+ // last one reflects the current state
+ const entry = entries[entries.length - 1];
- // If sentinel is not intersecting viewport, sticky element is stuck
- setIsSticky(!entry.isIntersecting);
+ setIsStickyStateChanging(true);
+ setIsSticky(isScrolledPastTop(entry));
requestAnimationFrame(() => {
setIsStickyStateChanging(false);
@@ -61,3 +63,15 @@ export function useIsParameterPanelSticky({
isStickyStateChanging,
} as const;
}
+
+// The sentinel also leaves the viewport when it's below the fold (e.g. in a short
+// window), but the sticky element is only stuck once the sentinel has scrolled up
+// past the top.
+function isScrolledPastTop(entry: IntersectionObserverEntry) {
+ if (entry.isIntersecting) {
+ return false;
+ }
+
+ const viewportBottom = entry.rootBounds?.bottom ?? window.innerHeight;
+ return entry.boundingClientRect.top < viewportBottom;
+}
diff --git a/frontend/src/metabase/dashboard/hooks/use-is-parameter-panel-sticky.unit.spec.tsx b/frontend/src/metabase/dashboard/hooks/use-is-parameter-panel-sticky.unit.spec.tsx
index 53f121ea5c4..c3db37f4ea5 100644
--- a/frontend/src/metabase/dashboard/hooks/use-is-parameter-panel-sticky.unit.spec.tsx
+++ b/frontend/src/metabase/dashboard/hooks/use-is-parameter-panel-sticky.unit.spec.tsx
@@ -23,17 +23,41 @@ describe("useIsParameterPanelSticky", () => {
let mockDisconnect: jest.Mock;
let intersectionCallback: IntersectionObserverCallback | null = null;
- const invokeIntersection = (isIntersecting: boolean) => {
+ const VIEWPORT = new DOMRect(0, 0, 1000, 800);
+
+ type SentinelPosition = "visible" | "above" | "below";
+
+ const SENTINEL_TOP: Record<SentinelPosition, number> = {
+ visible: 100,
+ above: -100,
+ below: VIEWPORT.bottom + 100,
+ };
+
+ const createEntry = (
+ position: SentinelPosition,
+ ): IntersectionObserverEntry => {
+ const entry = {
+ isIntersecting: position === "visible",
+ boundingClientRect: new DOMRect(0, SENTINEL_TOP[position], 1000, 1),
+ rootBounds: VIEWPORT,
+ };
+ // The hook only reads isIntersecting, boundingClientRect and rootBounds
+ return entry as IntersectionObserverEntry;
+ };
+
+ const invokeIntersections = (positions: SentinelPosition[]) => {
act(() => {
intersectionCallback?.(
- // Unjustified type cast. FIXME
- [{ isIntersecting } as IntersectionObserverEntry],
- // Unjustified type cast. FIXME
+ positions.map(createEntry),
+ // The hook's callback never reads the observer argument
{} as IntersectionObserver,
);
});
};
+ const invokeIntersection = (isIntersecting: boolean) =>
+ invokeIntersections([isIntersecting ? "visible" : "above"]);
+
beforeAll(() => {
originalIntersectionObserver = global.IntersectionObserver;
});
@@ -97,6 +121,32 @@ describe("useIsParameterPanelSticky", () => {
expect(result.current.isSticky).toBe(false);
});
+ it("does not set isSticky when the sentinel is below the viewport", async () => {
+ const { result } = setup();
+
+ await waitFor(() => {
+ expect(mockObserve).toHaveBeenCalledTimes(1);
+ });
+
+ invokeIntersections(["below"]);
+
+ expect(result.current.isSticky).toBe(false);
+ });
+
+ it("uses the latest entry when several are delivered at once", async () => {
+ const { result } = setup();
+
+ await waitFor(() => {
+ expect(mockObserve).toHaveBeenCalledTimes(1);
+ });
+
+ invokeIntersections(["above", "visible"]);
+ expect(result.current.isSticky).toBe(false);
+
+ invokeIntersections(["visible", "above"]);
+ expect(result.current.isSticky).toBe(true);
+ });
+
it("sets isStickyStateChanging to true and false before and after isSticky is changed", async () => {
const { result } = setup();