Skip to content

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

GDGT-3224: migrate TabRow to CSS modules to fix gradient theme issue (#82482)

Will Fryb084ade53957
diff --git a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_Narrow_With_Many_Tabs.png b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_Narrow_With_Many_Tabs.png
index 0ff5f475f62..ef62cfe4687 100644
Binary files a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_Narrow_With_Many_Tabs.png and b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_Narrow_With_Many_Tabs.png differ
diff --git a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_Narrow_With_Many_Tabs_Dark_Theme.png b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_Narrow_With_Many_Tabs_Dark_Theme.png
new file mode 100644
index 00000000000..c66e21442e4
Binary files /dev/null and b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_Narrow_With_Many_Tabs_Dark_Theme.png differ
diff --git a/frontend/src/metabase/common/components/TabList/TabList.module.css b/frontend/src/metabase/common/components/TabList/TabList.module.css
new file mode 100644
index 00000000000..2c767507df9
--- /dev/null
+++ b/frontend/src/metabase/common/components/TabList/TabList.module.css
@@ -0,0 +1,9 @@
+.content {
+ overflow-x: scroll;
+ scroll-behavior: smooth;
+ scrollbar-width: none;
+
+ &::-webkit-scrollbar {
+ display: none;
+ }
+}
diff --git a/frontend/src/metabase/common/components/TabList/TabList.styled.tsx b/frontend/src/metabase/common/components/TabList/TabList.styled.tsx
deleted file mode 100644
index 4e3cca2575f..00000000000
--- a/frontend/src/metabase/common/components/TabList/TabList.styled.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-export const TabListRoot = styled.div`
- position: relative;
-`;
-
-export const TabListContent = styled.div`
- scroll-behavior: smooth;
- height: 100%;
-`;
diff --git a/frontend/src/metabase/common/components/TabList/TabList.tsx b/frontend/src/metabase/common/components/TabList/TabList.tsx
index f2ef079d837..4024e09b527 100644
--- a/frontend/src/metabase/common/components/TabList/TabList.tsx
+++ b/frontend/src/metabase/common/components/TabList/TabList.tsx
@@ -2,11 +2,12 @@ import type { HTMLAttributes, ReactNode, Ref, UIEventHandler } from "react";
import { forwardRef, useContext, useMemo } from "react";
import { useUniqueId } from "metabase/common/hooks/use-unique-id";
+import { Box, Flex } from "metabase/ui";
import type { TabContextType } from "../Tab";
import { TabContext } from "../Tab";
-import { TabListContent, TabListRoot } from "./TabList.styled";
+import S from "./TabList.module.css";
export interface TabListProps<T> extends Omit<
HTMLAttributes<HTMLDivElement>,
@@ -18,7 +19,7 @@ export interface TabListProps<T> extends Omit<
children?: ReactNode;
}
-const TabListInner = forwardRef(function TabGroup<T>(
+export const TabList = forwardRef(function TabGroup<T>(
{ value, onChange, onScroll, children, ...props }: TabListProps<T>,
ref: Ref<HTMLDivElement>,
) {
@@ -32,18 +33,19 @@ const TabListInner = forwardRef(function TabGroup<T>(
const activeContext = outerContext.isDefault ? innerContext : outerContext;
return (
- <TabListRoot {...props} role="tablist">
- <TabListContent ref={ref} onScroll={onScroll}>
+ <Box pos="relative" {...props} role="tablist">
+ <Flex
+ className={S.content}
+ ref={ref}
+ h="100%"
+ align="end"
+ onScroll={onScroll}
+ >
{/* Unjustified type cast. FIXME */}
<TabContext.Provider value={activeContext as TabContextType}>
{children}
</TabContext.Provider>
- </TabListContent>
- </TabListRoot>
+ </Flex>
+ </Box>
);
});
-
-export const TabList = Object.assign(TabListInner, {
- Root: TabListRoot,
- Content: TabListContent,
-});
diff --git a/frontend/src/metabase/common/components/TabRow/TabRow.module.css b/frontend/src/metabase/common/components/TabRow/TabRow.module.css
new file mode 100644
index 00000000000..2bf9fdf8e52
--- /dev/null
+++ b/frontend/src/metabase/common/components/TabRow/TabRow.module.css
@@ -0,0 +1,33 @@
+.tabList {
+ width: 100%;
+}
+
+.scrollButton {
+ height: calc(100% - 2px);
+ cursor: pointer;
+ color: var(--mb-color-text-disabled);
+
+ &:hover {
+ color: var(--mb-color-core-brand);
+ }
+}
+
+.left {
+ left: 0;
+ background: linear-gradient(
+ to left,
+ transparent,
+ 8%,
+ var(--mb-color-background_page-primary)
+ );
+}
+
+.right {
+ right: 0;
+ background: linear-gradient(
+ to right,
+ transparent,
+ 8%,
+ var(--mb-color-background_page-primary)
+ );
+}
diff --git a/frontend/src/metabase/common/components/TabRow/TabRow.styled.tsx b/frontend/src/metabase/common/components/TabRow/TabRow.styled.tsx
deleted file mode 100644
index 643ec5303a7..00000000000
--- a/frontend/src/metabase/common/components/TabRow/TabRow.styled.tsx
+++ /dev/null
@@ -1,49 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import { TabList as BaseTabList } from "metabase/common/components/TabList";
-import { alpha } from "metabase/ui/colors";
-
-export const TabList = styled(BaseTabList)`
- width: 100%;
-
- ${BaseTabList.Content} {
- display: flex;
- align-items: end;
- overflow-x: scroll;
- /* Chrome */
- ::-webkit-scrollbar {
- display: none;
- }
-
- -ms-overflow-style: none; /* IE and Edge */
- scrollbar-width: none; /* Firefox */
- }
-`;
-
-interface ScrollButtonProps {
- direction: "left" | "right";
-}
-
-export const ScrollButton = styled.button<ScrollButtonProps>`
- position: absolute;
- cursor: pointer;
- height: calc(100% - 2px);
- top: 0;
- width: 3rem;
- text-align: ${(props) => props.direction};
- color: var(--mb-color-text-disabled);
-
- &:hover {
- color: var(--mb-color-core-brand);
- }
- ${(props) => props.direction}: 0;
-
- background: linear-gradient(
- to ${(props) => props.direction},
- ${() => alpha("background_page-primary", 0.1)},
- ${() => alpha("background_page-primary", 0.5)},
- 30%,
- var(--mb-color-background_page-primary)
- );
-`;
diff --git a/frontend/src/metabase/common/components/TabRow/TabRow.tsx b/frontend/src/metabase/common/components/TabRow/TabRow.tsx
index 17d235e9555..a521ea53999 100644
--- a/frontend/src/metabase/common/components/TabRow/TabRow.tsx
+++ b/frontend/src/metabase/common/components/TabRow/TabRow.tsx
@@ -25,12 +25,13 @@ import {
import { usePreviousDistinct } from "react-use";
import { ExplicitSize } from "metabase/common/components/ExplicitSize";
+import { TabList } from "metabase/common/components/TabList";
import { useDndSensors } from "metabase/common/hooks";
-import { Icon } from "metabase/ui";
+import { Box, Icon, rem } from "metabase/ui";
import type { TabListProps } from "../TabList/TabList";
-import { ScrollButton, TabList } from "./TabRow.styled";
+import S from "./TabRow.module.css";
import { tabsCollisionDetection } from "./collision-detection";
interface TabRowProps<T> extends TabListProps<T> {
@@ -108,6 +109,7 @@ const TabRowInner = forwardRef<HTMLDivElement, TabRowProps<unknown>>(
ref={mergedRef}
{...props}
className={cx(
+ S.tabList,
{
scrollable: showScrollLeft || showScrollRight,
},
@@ -150,12 +152,17 @@ interface ScrollArrowProps {
export function ScrollArrow({ direction, onClick }: ScrollArrowProps) {
return (
- <ScrollButton
+ <Box
+ component="button"
+ className={cx(S.scrollButton, S[direction])}
+ pos="absolute"
+ top={0}
+ w={rem(48)}
+ ta={direction}
onClick={onClick}
- direction={direction}
aria-label={`scroll tabs ${direction}`}
>
<Icon name={`chevron${direction}`} />
- </ScrollButton>
+ </Box>
);
}
diff --git a/frontend/src/metabase/public/containers/PublicOrEmbeddedDashboard/PublicOrEmbeddedDashboardView.stories.tsx b/frontend/src/metabase/public/containers/PublicOrEmbeddedDashboard/PublicOrEmbeddedDashboardView.stories.tsx
index a7a838712e6..4dc4b8f44e2 100644
--- a/frontend/src/metabase/public/containers/PublicOrEmbeddedDashboard/PublicOrEmbeddedDashboardView.stories.tsx
+++ b/frontend/src/metabase/public/containers/PublicOrEmbeddedDashboard/PublicOrEmbeddedDashboardView.stories.tsx
@@ -222,6 +222,15 @@ export const NarrowWithManyTabs = {
decorators: [NarrowDecorator],
};
+export const NarrowWithManyTabsDarkTheme = {
+ render: Template,
+ args: {
+ ...NarrowWithManyTabs.args,
+ theme: "night",
+ },
+ decorators: [NarrowDecorator, DarkBackgroundDecorator],
+};
+
export const LightThemeDefault = {
render: Template,
args: defaultArgs,