Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

refactor(TabList): keep size prop, remove density (#1418)

Ernest28d7299afb3b
diff --git a/apps/storybook/stories/TabList.stories.tsx b/apps/storybook/stories/TabList.stories.tsx
index 48df098141..241ad636b5 100644
--- a/apps/storybook/stories/TabList.stories.tsx
+++ b/apps/storybook/stories/TabList.stories.tsx
@@ -15,7 +15,7 @@ const meta: Meta<typeof XDSTabList> = {
size: {
control: 'select',
options: ['sm', 'md', 'lg'],
- description: 'Size variant for tabs',
+ description: 'Size of the tab hover targets',
},
},
};
@@ -89,36 +89,26 @@ export const SizeVariants: Story = {
const [value, setValue] = useState('home');
return (
<div style={{display: 'flex', flexDirection: 'column', gap: '24px'}}>
- <div>
- <div style={{marginBottom: '8px', fontSize: '12px', color: '#666'}}>
- Small
+ {(['sm', 'md', 'lg'] as const).map(size => (
+ <div key={size}>
+ <div
+ style={{
+ marginBottom: '8px',
+ fontSize: '12px',
+ color: '#666',
+ fontFamily: 'monospace',
+ }}>
+ size=\"{size}\"
+ </div>
+ <div style={{border: '1px dashed #ccc', display: 'inline-flex'}}>
+ <XDSTabList value={value} onChange={setValue} size={size}>
+ <XDSTab value="home" label="Home" />
+ <XDSTab value="projects" label="Projects" />
+ <XDSTab value="settings" label="Settings" />
+ </XDSTabList>
+ </div>
</div>
- <XDSTabList value={value} onChange={setValue} size="sm">
- <XDSTab value="home" label="Home" />
- <XDSTab value="projects" label="Projects" />
- <XDSTab value="settings" label="Settings" />
- </XDSTabList>
- </div>
- <div>
- <div style={{marginBottom: '8px', fontSize: '12px', color: '#666'}}>
- Medium (default)
- </div>
- <XDSTabList value={value} onChange={setValue} size="md">
- <XDSTab value="home" label="Home" />
- <XDSTab value="projects" label="Projects" />
- <XDSTab value="settings" label="Settings" />
- </XDSTabList>
- </div>
- <div>
- <div style={{marginBottom: '8px', fontSize: '12px', color: '#666'}}>
- Large
- </div>
- <XDSTabList value={value} onChange={setValue} size="lg">
- <XDSTab value="home" label="Home" />
- <XDSTab value="projects" label="Projects" />
- <XDSTab value="settings" label="Settings" />
- </XDSTabList>
- </div>
+ ))}
</div>
);
},
@@ -159,9 +149,6 @@ export const WithIcons: Story = {
/**
* Demonstrates a common page header pattern: large tab list items on the left
* with action buttons on the right, separated by a full-width divider underneath.
- *
- * Uses hasDivider on the TabList for a full-width divider that sits behind
- * the active tab's underline indicator.
*/
export const WithActions: Story = {
render: () => {
@@ -171,7 +158,13 @@ export const WithActions: Story = {
<XDSTab value="all" label="All items" />
<XDSTab value="active" label="Active" />
<XDSTab value="archived" label="Archived" />
- <div style={{marginInlineStart: 'auto', display: 'flex', alignItems: 'center', gap: '4px'}}>
+ <div
+ style={{
+ marginInlineStart: 'auto',
+ display: 'flex',
+ alignItems: 'center',
+ gap: '4px',
+ }}>
<XDSButton
label="Filter"
variant="ghost"
diff --git a/apps/storybook/stories/Toolbar.stories.tsx b/apps/storybook/stories/Toolbar.stories.tsx
index 03d2e1e0c0..68a27df007 100644
--- a/apps/storybook/stories/Toolbar.stories.tsx
+++ b/apps/storybook/stories/Toolbar.stories.tsx
@@ -1,5 +1,7 @@
+import {useState} from 'react';
import type {Meta, StoryObj} from '@storybook/react';
import {XDSToolbar} from '@xds/core/Toolbar';
+import {XDSTabList, XDSTab} from '@xds/core/TabList';
import {XDSButton} from '@xds/core/Button';
import {XDSCard} from '@xds/core/Card';
import {XDSSection} from '@xds/core/Section';
@@ -390,3 +392,45 @@ export const InsideLayout: Story = {
</div>
),
};
+
+/** Toolbar with tab navigation on the left and action buttons on the right. Tests that tab hover targets align with buttons at each size. */
+export const WithTabNavigation: Story = {
+ name: 'Composition: Tab Navigation',
+ render: () => {
+ const [tab, setTab] = useState('overview');
+ return (
+ <div style={{display: 'flex', flexDirection: 'column', gap: 24}}>
+ {(['sm', 'md', 'lg'] as const).map(size => (
+ <XDSCard key={size}>
+ <XDSToolbar
+ label={`Tab navigation (${size})`}
+ dividers={['bottom']}
+ startContent={
+ <XDSTabList value={tab} onChange={setTab} size={size}>
+ <XDSTab value="overview" label="Overview" />
+ <XDSTab value="analytics" label="Analytics" />
+ <XDSTab value="settings" label="Settings" />
+ </XDSTabList>
+ }
+ endContent={
+ <>
+ <XDSButton
+ label="Export"
+ variant="ghost"
+ size={size}
+ icon={<ArrowDownTrayIcon style={{width: 16, height: 16}} />}
+ isIconOnly
+ />
+ <XDSButton label="New item" size={size} />
+ </>
+ }
+ />
+ <XDSSection>
+ <XDSText>Content for {size} size variant</XDSText>
+ </XDSSection>
+ </XDSCard>
+ ))}
+ </div>
+ );
+ },
+};
diff --git a/packages/core/src/TabList/XDSTab.tsx b/packages/core/src/TabList/XDSTab.tsx
index 2558512127..fbf982b0e7 100644
--- a/packages/core/src/TabList/XDSTab.tsx
+++ b/packages/core/src/TabList/XDSTab.tsx
@@ -119,7 +119,7 @@ const styles = stylex.create({
},
indicator: {
position: 'absolute',
- bottom: 0,
+ bottom: '-2px',
left: spacingVars['--spacing-3'],
right: spacingVars['--spacing-3'],
height: '2px',
diff --git a/packages/core/src/TabList/XDSTabList.tsx b/packages/core/src/TabList/XDSTabList.tsx
index b45e893640..c1187ab603 100644
--- a/packages/core/src/TabList/XDSTabList.tsx
+++ b/packages/core/src/TabList/XDSTabList.tsx
@@ -33,7 +33,8 @@ export interface XDSTabListProps extends Omit<
*/
onChange: (value: string) => void;
/**
- * Size variant for all tabs.
+ * Size of the tab hover targets. Uses the same element size tokens
+ * as Button and TextInput (`sm` = 28px, `md` = 32px, `lg` = 36px).
* @default 'md'
*/
size?: XDSTabListSize;
diff --git a/packages/core/src/TabList/XDSTabListContext.ts b/packages/core/src/TabList/XDSTabListContext.ts
index 4d9aa49d47..8ecb6e0ff1 100644
--- a/packages/core/src/TabList/XDSTabListContext.ts
+++ b/packages/core/src/TabList/XDSTabListContext.ts
@@ -9,7 +9,6 @@
* SYNC: When modified, update /packages/core/src/TabList/TabList.doc.mjs
*/
-
import {createContext, useContext} from 'react';
/**
diff --git a/packages/core/src/TabList/XDSTabMenu.tsx b/packages/core/src/TabList/XDSTabMenu.tsx
index 7040c6f832..91d4783b20 100644
--- a/packages/core/src/TabList/XDSTabMenu.tsx
+++ b/packages/core/src/TabList/XDSTabMenu.tsx
@@ -112,7 +112,7 @@ const styles = stylex.create({
},
indicator: {
position: 'absolute',
- bottom: 0,
+ bottom: '-2px',
left: spacingVars['--spacing-3'],
right: spacingVars['--spacing-3'],
height: '2px',