Skip to content

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

Gdgt 2461 tabs (#82174)

Jakub Chodorowicz236a1cc9bda8
diff --git a/.loki/reference/chrome_laptop_Components_Navigation_Tabs_Overview_Overview.png b/.loki/reference/chrome_laptop_Components_Navigation_Tabs_Overview_Overview.png
new file mode 100644
index 00000000000..f690b62d59f
Binary files /dev/null and b/.loki/reference/chrome_laptop_Components_Navigation_Tabs_Overview_Overview.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_All_Options_Dark_Theme.png b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_All_Options_Dark_Theme.png
index be0ae02a0f4..33c55d48eb1 100644
Binary files a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_All_Options_Dark_Theme.png and b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_All_Options_Dark_Theme.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Exclude_Dark_Theme.png b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Exclude_Dark_Theme.png
index b34b44c92cc..5932e717fc3 100644
Binary files a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Exclude_Dark_Theme.png and b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Exclude_Dark_Theme.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Exclude_Day_Of_Week.png b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Exclude_Day_Of_Week.png
index a3d4152d481..74da8d87874 100644
Binary files a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Exclude_Day_Of_Week.png and b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Exclude_Day_Of_Week.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Exclude_Day_Of_Week_Dark_Theme.png b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Exclude_Day_Of_Week_Dark_Theme.png
index 584ca1c416d..6ca331d7d41 100644
Binary files a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Exclude_Day_Of_Week_Dark_Theme.png and b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Exclude_Day_Of_Week_Dark_Theme.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Current.png b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Current.png
index 712825a66ac..dbab96c312f 100644
Binary files a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Current.png and b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Current.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Current_Dark_Theme.png b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Current_Dark_Theme.png
index e1dd9cf6bd3..499b8a4f479 100644
Binary files a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Current_Dark_Theme.png and b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Current_Dark_Theme.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Next.png b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Next.png
index 2c1f14f2641..e94031c7d74 100644
Binary files a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Next.png and b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Next.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Next_Dark_Theme.png b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Next_Dark_Theme.png
index 713c7d47fe6..4b83b7a4fa5 100644
Binary files a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Next_Dark_Theme.png and b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Next_Dark_Theme.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Previous.png b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Previous.png
index 6136b79fffa..05028fed991 100644
Binary files a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Previous.png and b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Previous.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Previous_Dark_Theme.png b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Previous_Dark_Theme.png
index ae9cc7a9a0d..9588f5f5195 100644
Binary files a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Previous_Dark_Theme.png and b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Relative_Previous_Dark_Theme.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Specific_Between.png b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Specific_Between.png
index 527bb6fffac..f27d87adf06 100644
Binary files a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Specific_Between.png and b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Specific_Between.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Specific_Between_Dark_Theme.png b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Specific_Between_Dark_Theme.png
index febfddebd21..95c8a26f821 100644
Binary files a/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Specific_Between_Dark_Theme.png and b/.loki/reference/chrome_laptop_Components_Parameters_DatePicker_Specific_Between_Dark_Theme.png differ
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-inspector/pages/TransformInspectPage/components/LensNavigator/LensNavigator.css b/enterprise/frontend/src/metabase-enterprise/transforms-inspector/pages/TransformInspectPage/components/LensNavigator/LensNavigator.css
index efe77aebcb8..0c8a809ce9f 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms-inspector/pages/TransformInspectPage/components/LensNavigator/LensNavigator.css
+++ b/enterprise/frontend/src/metabase-enterprise/transforms-inspector/pages/TransformInspectPage/components/LensNavigator/LensNavigator.css
@@ -10,8 +10,5 @@
.tab {
max-width: 236px;
-
- &[data-orientation="horizontal"] {
- padding: 0.625rem 0.625rem 0.625rem var(--mantine-spacing-sm);
- }
+ padding-inline: var(--mantine-spacing-sm) 0.625rem;
}
diff --git a/frontend/src/metabase/admin/performance/components/PerformanceApp.module.css b/frontend/src/metabase/admin/performance/components/PerformanceApp.module.css
index 95fbb35088f..b50c3a35ddf 100644
--- a/frontend/src/metabase/admin/performance/components/PerformanceApp.module.css
+++ b/frontend/src/metabase/admin/performance/components/PerformanceApp.module.css
@@ -10,7 +10,7 @@
top: 1px;
margin-bottom: 1px;
border-bottom-width: 3px !important;
- padding: 0.625rem 0;
+ padding-inline: 0;
margin-inline-end: 1.25rem;
:hover {
diff --git a/frontend/src/metabase/common/components/Sidesheet/sidesheet.module.css b/frontend/src/metabase/common/components/Sidesheet/sidesheet.module.css
index ced651fe68a..e28abf5015b 100644
--- a/frontend/src/metabase/common/components/Sidesheet/sidesheet.module.css
+++ b/frontend/src/metabase/common/components/Sidesheet/sidesheet.module.css
@@ -32,12 +32,17 @@
}
}
-/* For divs that are not tabs but which sit next to the tabs */
+/* For divs that are not tabs but which sit next to the tabs. Reuses the
+ * `--tab-*` variables set on the `Tabs` root so it stays the same height,
+ * padding and type as the real tabs beside it. */
.TabSibling {
- padding: 0.6875rem 0.5rem;
+ align-items: center;
+ height: var(--tab-height);
+ padding: 0 var(--tab-padding-inline);
color: var(--mb-color-text-primary);
- font-weight: bold;
- line-height: 1rem;
+ font-size: var(--tab-font-size);
+ font-weight: var(--tab-font-weight);
+ line-height: var(--mantine-line-height-md);
&:hover {
color: var(--mb-color-core-brand);
diff --git a/frontend/src/metabase/dashboard/components/ParameterSidebar/ParameterSidebar.tsx b/frontend/src/metabase/dashboard/components/ParameterSidebar/ParameterSidebar.tsx
index 3cb491fe9a5..8825ad18258 100644
--- a/frontend/src/metabase/dashboard/components/ParameterSidebar/ParameterSidebar.tsx
+++ b/frontend/src/metabase/dashboard/components/ParameterSidebar/ParameterSidebar.tsx
@@ -252,18 +252,11 @@ export const ParameterSidebar = (): JSX.Element | null => {
}
data-testid="dashboard-parameter-sidebar"
>
- <Tabs radius={0} value={tab} onChange={handleTabChange}>
+ <Tabs value={tab} onChange={handleTabChange}>
{tabs.length > 1 && (
<Tabs.List grow>
{tabs.map((tab) => (
- <Tabs.Tab
- pl={0}
- pr={0}
- pt="lg"
- pb="lg"
- value={tab.value}
- key={tab.value}
- >
+ <Tabs.Tab value={tab.value} key={tab.value}>
{tab.name}
</Tabs.Tab>
))}
diff --git a/frontend/src/metabase/explorations/components/NewExplorationData/modals/AddMetricsModal.tsx b/frontend/src/metabase/explorations/components/NewExplorationData/modals/AddMetricsModal.tsx
index a170831f4fb..48821ffedc0 100644
--- a/frontend/src/metabase/explorations/components/NewExplorationData/modals/AddMetricsModal.tsx
+++ b/frontend/src/metabase/explorations/components/NewExplorationData/modals/AddMetricsModal.tsx
@@ -116,10 +116,9 @@ export function AddMetricsModal({
<Tabs.List>
<Tabs.Tab
value="library"
- px="lg"
leftSection={<Icon name="repository" size={14} />}
>{t`Library`}</Tabs.Tab>
- <Tabs.Tab value="all" px="lg">{t`All`}</Tabs.Tab>
+ <Tabs.Tab value="all">{t`All`}</Tabs.Tab>
</Tabs.List>
</Tabs>
) : undefined;
diff --git a/frontend/src/metabase/monitor/tools/notifications/NotificationsTabs/NotificationsTabs.module.css b/frontend/src/metabase/monitor/tools/notifications/NotificationsTabs/NotificationsTabs.module.css
deleted file mode 100644
index 0928bacfe56..00000000000
--- a/frontend/src/metabase/monitor/tools/notifications/NotificationsTabs/NotificationsTabs.module.css
+++ /dev/null
@@ -1,23 +0,0 @@
-.list {
- padding: 0;
-}
-
-.tab.tab {
- background-color: transparent;
- color: var(--mb-color-text-primary);
- gap: var(--mantine-spacing-sm);
-
- &:hover {
- background-color: var(--mb-color-background_surface-hover);
- }
-
- &[data-active="true"] {
- background-color: var(--mb-color-background_surface-selected);
- color: var(--mb-color-core-brand);
- }
-}
-
-.tabSection[data-position="left"],
-.tabSection[data-position="right"] {
- margin-inline: 0;
-}
diff --git a/frontend/src/metabase/monitor/tools/notifications/NotificationsTabs/NotificationsTabs.tsx b/frontend/src/metabase/monitor/tools/notifications/NotificationsTabs/NotificationsTabs.tsx
index 2ed5f5bc66e..c3655ee75d8 100644
--- a/frontend/src/metabase/monitor/tools/notifications/NotificationsTabs/NotificationsTabs.tsx
+++ b/frontend/src/metabase/monitor/tools/notifications/NotificationsTabs/NotificationsTabs.tsx
@@ -11,8 +11,6 @@ import type {
} from "../NotificationsAdminPage/types";
import { trackAlertsManagementTabClicked } from "../analytics";
-import S from "./NotificationsTabs.module.css";
-
type Props = {
tab: NotificationsTab;
allCount: TabCountState;
@@ -45,17 +43,17 @@ const TabCountBadge = ({
data-testid="tab-count-skeleton"
/>
))
- .with({ status: "loaded" }, ({ value }) =>
- isActive ? (
- <Badge variant="filled" size="xs" color="brand">
- {value}
- </Badge>
- ) : (
- <Badge variant="light" size="xs" color="neutral">
- {value}
- </Badge>
- ),
- )
+ .with({ status: "loaded" }, ({ value }) => (
+ <Badge
+ variant="light"
+ size="xs"
+ color="neutral"
+ bg={isActive ? "background_surface-secondary-hover" : undefined}
+ c={isActive ? "text-primary-inverse" : undefined}
+ >
+ {value}
+ </Badge>
+ ))
.with({ status: "error" }, () => null)
.exhaustive();
@@ -111,14 +109,7 @@ export const NotificationsTabs = ({
variant="pills"
value={tab}
onChange={handleTabChange}
- radius="xl"
data-testid="notifications-admin-tabs"
- classNames={{
- list: S.list,
- tab: S.tab,
- tabLabel: S.tabLabel,
- tabSection: S.tabSection,
- }}
>
<Tabs.List>
{tabs.map((config) => (
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/AddDataModal/AddDataModal.module.css b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/AddDataModal/AddDataModal.module.css
index 5ea1309eca8..a243153546c 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/AddDataModal/AddDataModal.module.css
+++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/AddDataModal/AddDataModal.module.css
@@ -1,4 +1,4 @@
-.tab {
+.list .tab {
height: 2.5rem;
border-radius: var(--mantine-radius-sm);
diff --git a/frontend/src/metabase/parameters/components/TagEditor/TagEditorSidebar.tsx b/frontend/src/metabase/parameters/components/TagEditor/TagEditorSidebar.tsx
index 2a0e12992cf..300377e76cc 100644
--- a/frontend/src/metabase/parameters/components/TagEditor/TagEditorSidebar.tsx
+++ b/frontend/src/metabase/parameters/components/TagEditor/TagEditorSidebar.tsx
@@ -77,7 +77,7 @@ export function TagEditorSidebar({
return (
<SidebarContent title={t`Variables and parameters`} onClose={onClose}>
<div data-testid="tag-editor-sidebar">
- <Tabs radius={0} value={section} onChange={handleTabChange}>
+ <Tabs value={section} onChange={handleTabChange}>
<Tabs.List grow>
<Tabs.Tab value="settings">{t`Settings`}</Tabs.Tab>
<Tabs.Tab value="help">{t`Help`}</Tabs.Tab>
diff --git a/frontend/src/metabase/querying/common/components/DatePicker/RelativeDatePicker/RelativeDatePicker.tsx b/frontend/src/metabase/querying/common/components/DatePicker/RelativeDatePicker/RelativeDatePicker.tsx
index e7ea499332c..de71193f2a4 100644
--- a/frontend/src/metabase/querying/common/components/DatePicker/RelativeDatePicker/RelativeDatePicker.tsx
+++ b/frontend/src/metabase/querying/common/components/DatePicker/RelativeDatePicker/RelativeDatePicker.tsx
@@ -68,7 +68,8 @@ export function RelativeDatePicker({
<Tabs value={direction} onChange={handleTabChange}>
<Flex>
<PopoverBackButton
- p="sm"
+ px="sm"
+ h="var(--tab-height)"
onClick={onBack}
disabled={readOnly}
withArrow={!readOnly}
diff --git a/frontend/src/metabase/querying/common/components/DatePicker/SpecificDatePicker/SpecificDatePicker.tsx b/frontend/src/metabase/querying/common/components/DatePicker/SpecificDatePicker/SpecificDatePicker.tsx
index 691a03f6028..24a4fe92062 100644
--- a/frontend/src/metabase/querying/common/components/DatePicker/SpecificDatePicker/SpecificDatePicker.tsx
+++ b/frontend/src/metabase/querying/common/components/DatePicker/SpecificDatePicker/SpecificDatePicker.tsx
@@ -82,7 +82,8 @@ export function SpecificDatePicker({
<Tabs value={value.operator} onChange={handleTabChange}>
<Flex>
<PopoverBackButton
- p="sm"
+ px="sm"
+ h="var(--tab-height)"
onClick={onBack}
disabled={readOnly}
withArrow={!readOnly}
diff --git a/frontend/src/metabase/ui/components/navigation/Tabs/Tab.module.css b/frontend/src/metabase/ui/components/navigation/Tabs/Tab.module.css
index f51c174aa5b..8046aeacbcf 100644
--- a/frontend/src/metabase/ui/components/navigation/Tabs/Tab.module.css
+++ b/frontend/src/metabase/ui/components/navigation/Tabs/Tab.module.css
@@ -1,71 +1,191 @@
-.list {
- --tab-border-color: var(--mb-color-border-neutral);
+.root {
+ --tab-height: 2rem;
+ --tab-padding-inline: var(--mantine-spacing-lg);
+ --tab-section-gap: var(--mantine-spacing-xs);
+ --tab-font-size: var(--mantine-font-size-md);
+ --tab-font-weight: 400;
- [data-orientation="horizontal"] {
- padding: 0.6875rem 0.5rem;
- }
+ &[data-variant="default"] {
+ --tabs-list-border-width: 1px;
+ --tab-active-border-width: 2px;
+ --tab-border-width: 0 0 var(--tab-active-border-width) 0;
- [data-orientation="vertical"] {
- padding: 0.6875rem 0.9375rem 0.6875rem 0.5rem;
- }
+ &[data-inverted] {
+ --tab-border-width: var(--tab-active-border-width) 0 0 0;
+ }
+
+ &[data-orientation="vertical"] {
+ --tab-border-width: 0 var(--tab-active-border-width) 0 0;
- &[data-orientation="vertical"] {
- .tabLabel {
- text-align: left; /* "start" for some reason doesn't work properly */
+ &[data-placement="right"] {
+ --tab-border-width: 0 0 0 var(--tab-active-border-width);
+ }
}
}
- &[data-variant="pills"] .tab {
- border-radius: 999px;
- padding: 0.6rem 1rem;
+ &[data-size="sm"] {
+ --tab-height: 1.5rem;
+ --tab-padding-inline: var(--mantine-spacing-md);
+ --tab-section-gap: var(--mantine-spacing-xxs);
+ --tab-font-size: var(--mantine-font-size-sm);
+ --tab-font-weight: 500;
+ }
+}
- &[data-active="true"] {
- background-color: var(--mb-color-background_surface-selected);
- color: var(--mb-color-core-brand);
- }
+.list {
+ --tab-border-color: var(--mb-color-border-neutral);
+
+ &[data-orientation="vertical"] .tabLabel {
+ text-align: left;
}
}
+.list::before {
+ border-width: var(--tabs-list-border-size);
+}
+
[data-list-border-hidden] .list::before {
border-width: 0;
}
.tab {
- color: var(--mb-color-text-primary);
+ height: var(--tab-height);
max-width: 100%;
+ padding: 0 var(--tab-padding-inline);
justify-content: start;
- padding: var(--mantine-spacing-xxs) var(--mantine-spacing-lg);
+ color: var(--mb-color-text-primary);
+ border-radius: 0;
&:hover {
- border-color: var(--mb-color-background_surface-hover);
- background-color: var(--mb-color-background_surface-hover);
+ background-color: var(--mb-color-background_surface-primary-hover);
+ border-color: transparent;
+ }
+
+ &:active {
+ background-color: var(--mb-color-background_surface-primary-pressed);
}
&:focus-visible {
outline: 2px solid var(--mb-color-input-focus);
}
+ &[data-active="true"] {
+ border-color: var(--mb-color-background_surface-brand-strong);
+ }
+
&:disabled {
color: var(--mb-color-text-disabled);
opacity: 1;
}
+}
+
+.tab[data-closable] {
+ --tab-close-size: 1rem;
+ --tab-close-transition: 150ms ease;
+
+ transition: padding-inline var(--tab-close-transition);
+
+ &:hover,
+ &:active,
+ &:focus-visible {
+ padding-inline: calc(var(--tab-padding-inline) - var(--tab-close-size) / 2);
+ }
+
+ &:disabled {
+ padding-inline: var(--tab-padding-inline);
+ }
+}
+
+.list[data-variant="pills"] .tab {
+ border-radius: var(--mantine-radius-lg);
&[data-active="true"] {
- color: var(--mb-color-text-brand);
- border-color: var(--mb-color-core-brand);
+ color: var(--mb-color-text-primary-inverse);
+ background-color: var(--mb-color-background_surface-brand-strong);
+
+ &:hover {
+ background-color: var(--mb-color-background_surface-brand-strong-hover);
+ }
+
+ &:active {
+ background-color: var(--mb-color-background_surface-brand-strong-pressed);
+ }
+ }
+
+ &:disabled,
+ &:disabled:hover {
+ background-color: var(--mb-color-background_surface-disabled);
}
}
.tabLabel {
- font-size: var(--mantine-font-size-md);
- font-weight: bold;
- line-height: 1.15; /* consistent w/ mantine v6 spacing */
+ font-size: var(--tab-font-size);
+ font-weight: var(--tab-font-weight);
+ line-height: var(--mantine-line-height-md);
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
text-align: center;
}
-.tabSection[data-position="left"] {
- margin-inline-end: 0.375rem;
+.tabSection {
+ &[data-position="left"]:not(:last-child) {
+ margin-inline-end: var(--tab-section-gap);
+ }
+
+ &[data-position="right"]:not(:first-child) {
+ margin-inline-start: var(--tab-section-gap);
+ }
+}
+
+.tabSection[data-position="right"]:has(> .tabClose:only-child) {
+ margin-inline-start: 0;
+}
+
+.tabClose {
+ display: inline-flex;
+ flex-shrink: 0;
+ align-items: center;
+ justify-content: center;
+ width: 0;
+ height: var(--tab-close-size);
+ overflow: hidden;
+ border-radius: var(--mantine-radius-xxs);
+ cursor: pointer;
+ opacity: 0;
+ transition:
+ width var(--tab-close-transition),
+ margin-inline-start var(--tab-close-transition),
+ opacity var(--tab-close-transition);
+
+ &:hover {
+ background-color: var(--mb-color-background_surface-primary-hover);
+ }
+}
+
+.tab:hover .tabClose,
+.tab:active .tabClose,
+.tab:focus-visible .tabClose {
+ width: var(--tab-close-size);
+ opacity: 1;
+
+ &:not(:first-child) {
+ margin-inline-start: var(--mantine-spacing-xxs);
+ }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .tab[data-closable],
+ .tabClose {
+ transition: none;
+ }
+}
+
+.tab:disabled .tabClose {
+ width: 0;
+ opacity: 0;
+}
+
+.list[data-variant="pills"] .tab[data-active="true"] .tabClose:hover {
+ background-color: var(--mb-color-background_surface-primary-inverse-hover);
}
diff --git a/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.config.tsx b/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.config.tsx
index 43d71731b41..7e010d40162 100644
--- a/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.config.tsx
+++ b/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.config.tsx
@@ -8,6 +8,7 @@ export const tabsOverrides: MantineThemeOverride["components"] = {
keepMounted: false,
},
classNames: {
+ root: TabStyles.root,
tab: TabStyles.tab,
list: TabStyles.list,
tabSection: TabStyles.tabSection,
diff --git a/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.mdx b/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.mdx
index 0f4a315e4b6..69a00a2ee94 100644
--- a/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.mdx
+++ b/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.mdx
@@ -35,6 +35,36 @@ Use the `pills` variant for a compact, toggle-like set of tabs.
<Canvas of={TabsStories.PillsIcons} />
+### Sizes
+
+`size` is `md` by default. `sm` exists only for the `pills` variant — passing it
+with any other variant is a type error.
+
+```tsx
+<Tabs variant="pills" size="sm">
+```
+
+### Closable tabs
+
+`closable` renders a close control on a `Tabs.Tab`; `onClose` receives the
+tab's value. The component doesn't remove anything itself: drop the tab from
+your list, and if it was the selected one, pick a new selection.
+
+The control appears while the tab is hovered, pressed or focused; the tab keeps
+its width and the label slides over to make room.
+
+Keyboard users close the focused tab with `Delete` or `Backspace`.
+
+```tsx
+<Tabs.Tab value="one" closable onClose={handleClose}>
+ One
+</Tabs.Tab>
+```
+
+<Canvas of={TabsStories.Closable} />
+
+<Canvas of={TabsStories.ClosablePills} />
+
### List border
The `listBorder` prop (default variant only) controls the divider rendered under
diff --git a/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.stories.tsx b/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.stories.tsx
index 7be0737abee..7d761f082c7 100644
--- a/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.stories.tsx
+++ b/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.stories.tsx
@@ -1,3 +1,5 @@
+import { useState } from "react";
+
import { Icon, Tabs, type TabsProps } from "metabase/ui";
import type { IconName } from "metabase-types/api";
@@ -72,6 +74,42 @@ const IconsTemplate = (args: TabsProps) => (
</Tabs>
);
+const ClosableTemplate = (args: TabsProps) => {
+ const [openTabs, setOpenTabs] = useState(tabs);
+ const [selected, setSelected] = useState<string | null>(tabs[0].value);
+
+ const handleClose = (value: string) => {
+ const remaining = openTabs.filter((tab) => tab.value !== value);
+ setOpenTabs(remaining);
+ if (selected === value) {
+ setSelected(remaining[0]?.value ?? null);
+ }
+ };
+
+ return (
+ <Tabs {...args} value={selected} onChange={setSelected}>
+ <Tabs.List>
+ {openTabs.map((tab) => (
+ <Tabs.Tab
+ key={tab.value}
+ value={tab.value}
+ disabled={tab.disabled}
+ closable
+ onClose={handleClose}
+ >
+ {tab.label}
+ </Tabs.Tab>
+ ))}
+ </Tabs.List>
+ {openTabs.map((tab) => (
+ <Tabs.Panel key={tab.value} value={tab.value}>
+ {tab.label}
+ </Tabs.Panel>
+ ))}
+ </Tabs>
+ );
+};
+
export default {
title: "Components/Navigation/Tabs",
component: Tabs,
@@ -125,3 +163,15 @@ export const PillsIcons = {
variant: "pills",
},
};
+
+export const Closable = {
+ render: ClosableTemplate,
+};
+
+export const ClosablePills = {
+ render: ClosableTemplate,
+ name: "Closable, pills",
+ args: {
+ variant: "pills",
+ },
+};
diff --git a/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.tsx b/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.tsx
index 47b0a874725..a45e7979a1d 100644
--- a/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.tsx
+++ b/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.tsx
@@ -3,25 +3,44 @@ import {
type TabsProps as MantineTabsProps,
} from "@mantine/core";
-export interface TabsProps<T extends string = string> extends Omit<
+import { TabsTab } from "./TabsTab";
+
+export type TabsSize = "sm" | "md";
+
+const DEFAULT_SIZE: TabsSize = "md";
+
+/**
+ * `sm` exists only for the `pills` variant; the underlined default variant
+ * comes in a single size.
+ */
+type TabsVariantProps =
+ | { variant: "pills"; size?: TabsSize }
+ | {
+ variant?: Exclude<MantineTabsProps["variant"], "pills">;
+ size?: typeof DEFAULT_SIZE;
+ };
+
+export type TabsProps<T extends string = string> = Omit<
MantineTabsProps,
- "value" | "defaultValue" | "onChange"
-> {
- value?: T | null;
- defaultValue?: T | null;
- // Need to keep 'null' option here, because Tabs has `allowTabDeactivation`
- // prop which leads to null value being passed to onChange.
- onChange?: (value: T | null) => void;
- /**
- * Whether the tab list renders its own divider line. Only applies to the
- * default (underlined) variant; ignored for `pills`, `outline`, etc.
- */
- listBorder?: boolean;
-}
+ "value" | "defaultValue" | "onChange" | "variant"
+> &
+ TabsVariantProps & {
+ value?: T | null;
+ defaultValue?: T | null;
+ // Need to keep 'null' option here, because Tabs has `allowTabDeactivation`
+ // prop which leads to null value being passed to onChange.
+ onChange?: (value: T | null) => void;
+ /**
+ * Whether the tab list renders its own divider line. Only applies to the
+ * default (underlined) variant; ignored for `pills`, `outline`, etc.
+ */
+ listBorder?: boolean;
+ };
function TabsRoot<T extends string = string>({
listBorder = true,
variant,
+ size = DEFAULT_SIZE,
onChange,
...props
}: TabsProps<T>) {
@@ -36,6 +55,7 @@ function TabsRoot<T extends string = string>({
// the `Tabs.Tab` values. But we know that the emitted value is always one of those,
// so we can safely cast it to the expected type.
onChange={onChange as MantineTabsProps["onChange"]}
+ data-size={size}
data-list-border-hidden={hideListBorder || undefined}
/>
);
@@ -43,6 +63,6 @@ function TabsRoot<T extends string = string>({
export const Tabs = Object.assign(TabsRoot, {
List: MantineTabs.List,
- Tab: MantineTabs.Tab,
+ Tab: TabsTab,
Panel: MantineTabs.Panel,
});
diff --git a/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.unit.spec.tsx b/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.unit.spec.tsx
new file mode 100644
index 00000000000..b400417d41b
--- /dev/null
+++ b/frontend/src/metabase/ui/components/navigation/Tabs/Tabs.unit.spec.tsx
@@ -0,0 +1,37 @@
+import { renderWithProviders, screen } from "__support__/ui";
+
+import { Tabs, type TabsProps } from "./Tabs";
+
+function setup(props: TabsProps = {}) {
+ renderWithProviders(
+ <Tabs data-testid="tabs" defaultValue="one" {...props}>
+ <Tabs.List>
+ <Tabs.Tab value="one">One</Tabs.Tab>
+ <Tabs.Tab value="two">Two</Tabs.Tab>
+ </Tabs.List>
+ </Tabs>,
+ );
+
+ return screen.getByTestId("tabs");
+}
+
+describe("Tabs", () => {
+ describe("size", () => {
+ it("defaults to md", () => {
+ expect(setup()).toHaveAttribute("data-size", "md");
+ });
+
+ it("exposes sm on the root for the pills variant", () => {
+ expect(setup({ variant: "pills", size: "sm" })).toHaveAttribute(
+ "data-size",
+ "sm",
+ );
+ });
+
+ it("only accepts sm together with the pills variant", () => {
+ // @ts-expect-error -- sm is a pills-only size
+ const props: TabsProps = { size: "sm" };
+ expect(setup(props)).toHaveAttribute("data-size", "sm");
+ });
+ });
+});
diff --git a/frontend/src/metabase/ui/components/navigation/Tabs/TabsOverview.stories.tsx b/frontend/src/metabase/ui/components/navigation/Tabs/TabsOverview.stories.tsx
new file mode 100644
index 00000000000..7518c2dbc99
--- /dev/null
+++ b/frontend/src/metabase/ui/components/navigation/Tabs/TabsOverview.stories.tsx
@@ -0,0 +1,384 @@
+import { action } from "@storybook/addon-actions";
+import { Fragment, type ReactNode, useState } from "react";
+
+import {
+ Badge,
+ Box,
+ Group,
+ Icon,
+ Kbd,
+ Tabs,
+ type TabsProps,
+ Text,
+} from "metabase/ui";
+import { StorySection, StoryShowcase } from "metabase/ui/stories/showcase";
+import type { IconName } from "metabase-types/api";
+
+const LABEL = "Value";
+const TAB_ICON: IconName = "model";
+
+// The `variant × size` combinations the design system supports; `sm` exists
+// only for pills.
+const COLUMNS = [
+ { tabsProps: { variant: "default", size: "md" }, width: "22rem" },
+ { tabsProps: { variant: "pills", size: "md" }, width: "22rem" },
+ { tabsProps: { variant: "pills", size: "sm" }, width: "18rem" },
+] as const satisfies readonly {
+ tabsProps: Pick<TabsProps, "variant" | "size">;
+ width: string;
+}[];
+
+type TabsColumn = (typeof COLUMNS)[number];
+
+type TabState = {
+ id: string;
+ label: string;
+ selected?: boolean;
+ disabled?: boolean;
+};
+
+const STATES: TabState[] = [
+ { id: "default", label: "Default" },
+ { id: "hover", label: "Hover" },
+ { id: "pressed", label: "Pressed" },
+ { id: "selected", label: "Selected", selected: true },
+ { id: "hover-selected", label: "Selected + hover", selected: true },
+ { id: "disabled", label: "Disabled", disabled: true },
+];
+
+const PSEUDO_STATE_PARAMETERS = {
+ pseudo: {
+ hover: ["[data-state-row='hover']", "[data-state-row='hover-selected']"],
+ active: ["[data-state-row='pressed']"],
+ },
+};
+
+type ContentKind = "text" | "icon-text" | "icon";
+
+const CONTENT_KINDS: { kind: ContentKind; label: string }[] = [
+ { kind: "text", label: "Text" },
+ { kind: "icon-text", label: "Icon + text" },
+ { kind: "icon", label: "Icon only" },
+];
+
+const SELECTED_TAB = "two";
+
+// On a brand-filled selected pill the Badge and Kbd switch to the design's
+// "Inverse" look: a translucent dark disc with inverse text.
+const INVERSE_PROPS = {
+ bg: "background_surface-secondary-hover",
+ c: "text-primary-inverse",
+} as const;
+
+function TabBadge({ inverse }: { inverse: boolean }) {
+ const badgeProps = inverse ? INVERSE_PROPS : {};
+
+ return (
+ <Badge variant="light" color="neutral" {...badgeProps}>
+ 1
+ </Badge>
+ );
+}
+
+function TabKbd({ inverse }: { inverse: boolean }) {
+ const kbdProps = inverse ? INVERSE_PROPS : {};
+
+ return (
+ <Group gap="xxxs" wrap="nowrap">
+ <Kbd {...kbdProps}>⌘</Kbd>
+ <Kbd {...kbdProps}>C</Kbd>
+ </Group>
+ );
+}
+
+type RightSectionRenderer = (args: { isSelectedPill: boolean }) => ReactNode;
+
+const RIGHT_SECTIONS: {
+ id: string;
+ label: string;
+ render: RightSectionRenderer;
+}[] = [
+ { id: "icon", label: "Icon", render: () => <Icon name={TAB_ICON} /> },
+ {
+ id: "kbd",
+ label: "Kbd",
+ render: ({ isSelectedPill }) => <TabKbd inverse={isSelectedPill} />,
+ },
+ {
+ id: "badge",
+ label: "Badge",
+ render: ({ isSelectedPill }) => <TabBadge inverse={isSelectedPill} />,
+ },
+];
+
+type ExampleTab = {
+ value: string;
+ content: ContentKind;
+ rightSection?: ReactNode;
+ disabled?: boolean;
+ closable?: boolean;
+ stateRow?: string;
+};
+
+type ExampleTabsProps = Pick<TabsProps, "orientation" | "onChange"> & {
+ column: TabsColumn;
+ tabs: ExampleTab[];
+ selected: string | null;
+ listBorder?: boolean;
+ onClose?: (value: string) => void;
+};
+
+function ExampleTabs({
+ column,
+ orientation,
+ tabs,
+ selected,
+ listBorder = true,
+ onChange = action("onChange"),
+ onClose = action("onClose"),
+}: ExampleTabsProps) {
+ return (
+ <Tabs
+ {...column.tabsProps}
+ orientation={orientation}
+ value={selected}
+ onChange={onChange}
+ listBorder={listBorder}
+ >
+ <Tabs.List>
+ {tabs.map((tab) => {
+ const leftSection =
+ tab.content !== "text" ? <Icon name={TAB_ICON} /> : undefined;
+
+ return (
+ <Tabs.Tab
+ key={tab.value}
+ value={tab.value}
+ disabled={tab.disabled}
+ closable={tab.closable}
+ onClose={onClose}
+ data-state-row={tab.stateRow}
+ leftSection={leftSection}
+ rightSection={tab.rightSection}
+ >
+ {tab.content !== "icon" ? LABEL : undefined}
+ </Tabs.Tab>
+ );
+ })}
+ </Tabs.List>
+ </Tabs>
+ );
+}
+
+function SingleTab({
+ column,
+ state,
+ content = "text",
+}: {
+ column: TabsColumn;
+ state: TabState;
+ content?: ContentKind;
+}) {
+ return (
+ <ExampleTabs
+ column={column}
+ listBorder={false}
+ selected={state.selected ? "tab" : null}
+ tabs={[
+ { value: "tab", content, disabled: state.disabled, stateRow: state.id },
+ ]}
+ />
+ );
+}
+
+function VariantGrid({ children }: { children: ReactNode }) {
+ return (
+ <Box
+ style={{
+ display: "grid",
+ gridTemplateColumns: `9rem ${COLUMNS.map(({ width }) => width).join(" ")}`,
+ columnGap: "2rem",
+ rowGap: "0.5rem",
+ alignItems: "center",
+ }}
+ >
+ {children}
+ </Box>
+ );
+}
+
+function VariantRow({
+ label,
+ render,
+}: {
+ label?: ReactNode;
+ render: (column: TabsColumn) => ReactNode;
+}) {
+ return (
+ <>
+ <Text size="sm" c="text-secondary">
+ {label}
+ </Text>
+ {COLUMNS.map((column) => (
+ <Fragment key={`${column.tabsProps.variant}-${column.tabsProps.size}`}>
+ {render(column)}
+ </Fragment>
+ ))}
+ </>
+ );
+}
+
+function getListOfTabs(tab: Omit<ExampleTab, "value">): ExampleTab[] {
+ return [
+ { ...tab, value: "one" },
+ { ...tab, value: SELECTED_TAB },
+ { ...tab, value: "three", disabled: true },
+ ];
+}
+
+function getTabsWithRightSection(
+ column: TabsColumn,
+ render: RightSectionRenderer,
+): ExampleTab[] {
+ const isPills = column.tabsProps.variant === "pills";
+
+ return getListOfTabs({ content: "text" }).map((tab) => ({
+ ...tab,
+ rightSection: render({
+ isSelectedPill: isPills && tab.value === SELECTED_TAB,
+ }),
+ }));
+}
+
+function ClosableTabs({
+ column,
+ content,
+}: {
+ column: TabsColumn;
+ content: ContentKind;
+}) {
+ // The first tab is forced into its hover state so the close control, which
+ // is only revealed on hover, shows up in the static showcase.
+ const [tabs, setTabs] = useState(() =>
+ getListOfTabs({ content, closable: true }).map((tab, index) =>
+ index === 0 ? { ...tab, stateRow: "hover" } : tab,
+ ),
+ );
+ const [selected, setSelected] = useState<string | null>(SELECTED_TAB);
+
+ const handleClose = (value: string) => {
+ const remaining = tabs.filter((tab) => tab.value !== value);
+ setTabs(remaining);
+ if (selected === value) {
+ setSelected(remaining[0]?.value ?? null);
+ }
+ };
+
+ return (
+ <ExampleTabs
+ column={column}
+ tabs={tabs}
+ selected={selected}
+ onChange={setSelected}
+ onClose={handleClose}
+ />
+ );
+}
+
+function OverviewTemplate() {
+ return (
+ <StoryShowcase title="Tabs">
+ <StorySection title="States">
+ <VariantGrid>
+ {STATES.map((state) => (
+ <VariantRow
+ key={state.id}
+ label={state.label}
+ render={(column) => <SingleTab column={column} state={state} />}
+ />
+ ))}
+ </VariantGrid>
+ </StorySection>
+
+ <StorySection title="Content">
+ <VariantGrid>
+ {CONTENT_KINDS.map(({ kind, label }) => (
+ <VariantRow
+ key={kind}
+ label={label}
+ render={(column) => (
+ <ExampleTabs
+ column={column}
+ selected={SELECTED_TAB}
+ tabs={getListOfTabs({ content: kind })}
+ />
+ )}
+ />
+ ))}
+ </VariantGrid>
+ </StorySection>
+
+ <StorySection title="Right section">
+ <VariantGrid>
+ {RIGHT_SECTIONS.map(({ id, label, render }) => (
+ <VariantRow
+ key={id}
+ label={label}
+ render={(column) => (
+ <ExampleTabs
+ column={column}
+ selected={SELECTED_TAB}
+ tabs={getTabsWithRightSection(column, render)}
+ />
+ )}
+ />
+ ))}
+ </VariantGrid>
+ </StorySection>
+
+ <StorySection title="Closable">
+ <VariantGrid>
+ {CONTENT_KINDS.filter(({ kind }) => kind !== "icon").map(
+ ({ kind, label }) => (
+ <VariantRow
+ key={kind}
+ label={label}
+ render={(column) => (
+ <ClosableTabs column={column} content={kind} />
+ )}
+ />
+ ),
+ )}
+ </VariantGrid>
+ </StorySection>
+
+ <StorySection title="Vertical orientation">
+ <VariantGrid>
+ <VariantRow
+ render={(column) => (
+ <ExampleTabs
+ column={column}
+ orientation="vertical"
+ selected={SELECTED_TAB}
+ tabs={getListOfTabs({ content: "icon-text" })}
+ />
+ )}
+ />
+ </VariantGrid>
+ </StorySection>
+ </StoryShowcase>
+ );
+}
+
+export default {
+ title: "Components/Navigation/Tabs/Overview",
+ component: Tabs,
+};
+
+export const Overview = {
+ render: OverviewTemplate,
+ parameters: {
+ ...PSEUDO_STATE_PARAMETERS,
+ controls: { include: ["theme"] },
+ },
+};
diff --git a/frontend/src/metabase/ui/components/navigation/Tabs/TabsTab.tsx b/frontend/src/metabase/ui/components/navigation/Tabs/TabsTab.tsx
new file mode 100644
index 00000000000..3a5c6a824c1
--- /dev/null
+++ b/frontend/src/metabase/ui/components/navigation/Tabs/TabsTab.tsx
@@ -0,0 +1,88 @@
+import { Tabs as MantineTabs } from "@mantine/core";
+import {
+ type ComponentPropsWithoutRef,
+ type KeyboardEvent,
+ type MouseEvent,
+ forwardRef,
+ useCallback,
+} from "react";
+
+import { Icon } from "../../icons";
+
+import S from "./Tab.module.css";
+
+const CLOSE_KEYS = ["Delete", "Backspace"];
+const CLOSE_ICON_SIZE = 12;
+
+// Derived from the component rather than Mantine's `TabsTabProps` so the
+// factory-level props (`renderRoot`, `component`) stay available to callers.
+type MantineTabsTabProps = ComponentPropsWithoutRef<typeof MantineTabs.Tab>;
+
+export interface TabsTabProps extends MantineTabsTabProps {
+ /**
+ * Renders a close control on the tab. Removing the tab is the caller's job:
+ * handle `onClose` and drop the tab (and pick a new selection if the closed
+ * one was active).
+ */
+ closable?: boolean;
+ onClose?: (value: string) => void;
+}
+
+/**
+ * The close control is a plain icon, not a button: a `<button>` cannot contain
+ * another interactive element. Keyboard users close the focused tab with
+ * `Delete` / `Backspace`, following the WAI-ARIA tabs pattern.
+ */
+export const TabsTab = forwardRef<HTMLButtonElement, TabsTabProps>(
+ function TabsTab(
+ { closable, onClose, value, rightSection, onKeyDown, ...props },
+ ref,
+ ) {
+ const handleCloseClick = useCallback(
+ (event: MouseEvent<HTMLSpanElement>) => {
+ event.preventDefault();
+ event.stopPropagation();
+ onClose?.(value);
+ },
+ [onClose, value],
+ );
+
+ const handleKeyDown = useCallback(
+ (event: KeyboardEvent<HTMLButtonElement>) => {
+ onKeyDown?.(event);
+ if (closable && CLOSE_KEYS.includes(event.key)) {
+ event.preventDefault();
+ onClose?.(value);
+ }
+ },
+ [closable, onClose, onKeyDown, value],
+ );
+
+ return (
+ <MantineTabs.Tab
+ ref={ref}
+ value={value}
+ onKeyDown={handleKeyDown}
+ data-closable={closable || undefined}
+ rightSection={
+ closable ? (
+ <>
+ {rightSection}
+ <span
+ className={S.tabClose}
+ data-testid="tab-close"
+ aria-hidden
+ onClick={handleCloseClick}
+ >
+ <Icon name="close" size={CLOSE_ICON_SIZE} />
+ </span>
+ </>
+ ) : (
+ rightSection
+ )
+ }
+ {...props}
+ />
+ );
+ },
+);
diff --git a/frontend/src/metabase/ui/components/navigation/Tabs/TabsTab.unit.spec.tsx b/frontend/src/metabase/ui/components/navigation/Tabs/TabsTab.unit.spec.tsx
new file mode 100644
index 00000000000..78000f4af07
--- /dev/null
+++ b/frontend/src/metabase/ui/components/navigation/Tabs/TabsTab.unit.spec.tsx
@@ -0,0 +1,93 @@
+import userEvent from "@testing-library/user-event";
+
+import { renderWithProviders, screen, within } from "__support__/ui";
+
+import { Tabs } from "./Tabs";
+import type { TabsTabProps } from "./TabsTab";
+
+function setup(props: Partial<TabsTabProps> = {}) {
+ const onChange = jest.fn();
+ const onClose = jest.fn();
+
+ renderWithProviders(
+ <Tabs value="one" onChange={onChange}>
+ <Tabs.List>
+ <Tabs.Tab value="one" onClose={onClose} {...props}>
+ One
+ </Tabs.Tab>
+ <Tabs.Tab value="two">Two</Tabs.Tab>
+ </Tabs.List>
+ </Tabs>,
+ );
+
+ return { onChange, onClose, tab: screen.getByRole("tab", { name: /One/ }) };
+}
+
+describe("Tabs.Tab", () => {
+ it("renders no close control by default", () => {
+ const { tab } = setup();
+
+ expect(within(tab).queryByTestId("tab-close")).not.toBeInTheDocument();
+ expect(tab).not.toHaveAttribute("data-closable");
+ });
+
+ describe("closable", () => {
+ it("marks the tab and renders the close control after the right section", () => {
+ const { tab } = setup({ closable: true, rightSection: "right" });
+
+ expect(tab).toHaveAttribute("data-closable", "true");
+ expect(tab).toHaveTextContent(/right$/);
+ expect(within(tab).getByTestId("tab-close")).toBeInTheDocument();
+ });
+
+ it("does not nest an interactive element inside the tab", () => {
+ const { tab } = setup({ closable: true });
+
+ expect(within(tab).queryByRole("button")).not.toBeInTheDocument();
+ });
+
+ it("calls onClose with the tab value on click without selecting the tab", async () => {
+ const { tab, onChange, onClose } = setup({ closable: true });
+
+ await userEvent.click(within(tab).getByTestId("tab-close"));
+
+ expect(onClose).toHaveBeenCalledWith("one");
+ expect(onChange).not.toHaveBeenCalled();
+ });
+
+ it("does not trigger the root's default action when the root is a link", async () => {
+ const { tab, onClose } = setup({
+ closable: true,
+ renderRoot: (props) => <a href="#two" {...props} />,
+ });
+
+ await userEvent.click(within(tab).getByTestId("tab-close"));
+
+ expect(onClose).toHaveBeenCalledWith("one");
+ expect(window.location.hash).toBe("");
+ });
+
+ it.each(["{Delete}", "{Backspace}"])(
+ "calls onClose when %s is pressed on the focused tab",
+ async (key) => {
+ const { tab, onClose } = setup({ closable: true });
+
+ tab.focus();
+ await userEvent.keyboard(key);
+
+ expect(onClose).toHaveBeenCalledWith("one");
+ },
+ );
+
+ it("keeps the caller's onKeyDown and does not close when not closable", async () => {
+ const onKeyDown = jest.fn();
+ const { tab, onClose } = setup({ onKeyDown });
+
+ tab.focus();
+ await userEvent.keyboard("{Delete}");
+
+ expect(onKeyDown).toHaveBeenCalled();
+ expect(onClose).not.toHaveBeenCalled();
+ });
+ });
+});
diff --git a/frontend/src/metabase/ui/components/navigation/Tabs/index.ts b/frontend/src/metabase/ui/components/navigation/Tabs/index.ts
index 1565fa2db20..b8d98a84469 100644
--- a/frontend/src/metabase/ui/components/navigation/Tabs/index.ts
+++ b/frontend/src/metabase/ui/components/navigation/Tabs/index.ts
@@ -1,8 +1,5 @@
export { Tabs } from "./Tabs";
-export type { TabsProps } from "./Tabs";
-export type {
- TabsTabProps,
- TabsListProps,
- TabsPanelProps,
-} from "@mantine/core";
+export type { TabsProps, TabsSize } from "./Tabs";
+export type { TabsTabProps } from "./TabsTab";
+export type { TabsListProps, TabsPanelProps } from "@mantine/core";
export { tabsOverrides } from "./Tabs.config";
diff --git a/frontend/src/metabase/visualizations/components/ChartSettingsWidgetPopover.tsx b/frontend/src/metabase/visualizations/components/ChartSettingsWidgetPopover.tsx
index daf4a15220a..6832cccf140 100644
--- a/frontend/src/metabase/visualizations/components/ChartSettingsWidgetPopover.tsx
+++ b/frontend/src/metabase/visualizations/components/ChartSettingsWidgetPopover.tsx
@@ -99,11 +99,7 @@ export const ChartSettingsWidgetPopover = ({
>
<Tabs.List grow>
{sections.current.map((sectionName) => (
- <Tabs.Tab
- key={sectionName}
- value={String(sectionName)}
- p="lg"
- >
+ <Tabs.Tab key={sectionName} value={String(sectionName)}>
{sectionName}
</Tabs.Tab>
))}
diff --git a/loki.config.js b/loki.config.js
index 2b2f88313d2..d88b7db6d08 100644
--- a/loki.config.js
+++ b/loki.config.js
@@ -27,6 +27,7 @@ module.exports = {
"^Components/Ask Before Using/Chip Overview",
"^Components/Data display/Badge Sizes and variants",
"^Components/Navigation/NavLink Overview",
+ "^Components/Navigation/Tabs/Overview",
"^Components/Data display/KeyboardShortcut Overview",
"^Components/Table",
"^Components/Inputs/PasswordInput Overview",