Skip to content

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

TypeScript

feat(TabList): visual polish — ghost hover, primary colors, divider overlap (#1357)

Ernest60b2d1158884
diff --git a/apps/storybook/stories/TabList.stories.tsx b/apps/storybook/stories/TabList.stories.tsx
index 442c561e00..48df098141 100644
--- a/apps/storybook/stories/TabList.stories.tsx
+++ b/apps/storybook/stories/TabList.stories.tsx
@@ -131,7 +131,6 @@ export const WithIcons: Story = {
render: args => {
const [value, setValue] = useState('home');
- // Inline SVG icons for the story
const HomeIcon = (
<svg viewBox="0 0 16 16" fill="currentColor" width="100%" height="100%">
<path d="M8.543 2.232a.75.75 0 0 0-1.085 0l-5.25 5.5A.75.75 0 0 0 2.75 9H4v4a1 1 0 0 0 1 1h2a1 1 0 0 0 1-1v-2h1v2a1 1 0 0 0 1 1h2a1 1 0 0 0 1-1V9h1.25a.75.75 0 0 0 .543-1.268l-5.25-5.5Z" />
@@ -161,41 +160,47 @@ 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 `XDSHStack` with `XDSStackItem size="fill"` to push the actions to the
- * trailing edge, and `XDSDivider` below for visual separation from page content.
+ * Uses hasDivider on the TabList for a full-width divider that sits behind
+ * the active tab's underline indicator.
*/
export const WithActions: Story = {
render: () => {
const [value, setValue] = useState('all');
return (
- <div>
- <XDSHStack vAlign="center">
- <XDSStackItem size="fill">
- <XDSTabList value={value} onChange={setValue} size="lg">
- <XDSTab value="all" label="All items" />
- <XDSTab value="active" label="Active" />
- <XDSTab value="archived" label="Archived" />
- </XDSTabList>
- </XDSStackItem>
- <XDSStackItem>
- <XDSHStack gap={1} vAlign="center">
- <XDSButton
- label="Filter"
- variant="ghost"
- size="md"
- icon={<FunnelIcon />}
- isIconOnly
- />
- <XDSButton
- label="New item"
- variant="primary"
- size="md"
- icon={<PlusIcon />}
- />
- </XDSHStack>
- </XDSStackItem>
- </XDSHStack>
- <XDSDivider />
+ <XDSTabList value={value} onChange={setValue} size="lg" hasDivider>
+ <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'}}>
+ <XDSButton
+ label="Filter"
+ variant="ghost"
+ size="sm"
+ icon={<FunnelIcon />}
+ isIconOnly
+ />
+ <XDSButton
+ label="New item"
+ variant="primary"
+ size="sm"
+ icon={<PlusIcon />}
+ />
+ </div>
+ </XDSTabList>
+ );
+ },
+};
+
+export const FillLayout: Story = {
+ render: () => {
+ const [value, setValue] = useState('home');
+ return (
+ <div style={{width: '500px'}}>
+ <XDSTabList value={value} onChange={setValue} layout="fill" hasDivider>
+ <XDSTab value="home" label="Home" />
+ <XDSTab value="projects" label="Projects" />
+ <XDSTab value="settings" label="Settings" />
+ </XDSTabList>
</div>
);
},
diff --git a/packages/core/src/TabList/XDSTab.tsx b/packages/core/src/TabList/XDSTab.tsx
index 16522841b9..54da66fded 100644
--- a/packages/core/src/TabList/XDSTab.tsx
+++ b/packages/core/src/TabList/XDSTab.tsx
@@ -27,6 +27,7 @@ import {
} from '../theme/tokens.stylex';
import {useXDSTabListContext} from './XDSTabListContext';
import type {XDSTabListSize} from './XDSTabListContext';
+import {tabScope} from './tab.markers.stylex';
import {useXDSLinkComponent} from '../Link/useXDSLinkComponent';
import type {XDSLinkComponentType} from '../Link/types';
import {xdsClassName, mergeProps} from '../utils';
@@ -115,8 +116,25 @@ const styles = stylex.create({
':focus-visible': '2px',
},
},
+ hoverBg: {
+ position: 'absolute',
+ inset: 0,
+ margin: 'auto',
+ width: '100%',
+ borderRadius: radiusVars['--radius-element'],
+ pointerEvents: 'none',
+ backgroundColor: {
+ default: 'transparent',
+ [stylex.when.ancestor(':hover', tabScope)]: {
+ '@media (hover: hover)': colorVars['--color-overlay-hover'],
+ },
+ },
+ transitionProperty: 'background-color',
+ transitionDuration: durationVars['--duration-fast'],
+ transitionTimingFunction: easeVars['--ease-standard'],
+ },
selected: {
- color: colorVars['--color-text-accent'],
+ color: colorVars['--color-text-primary'],
fontWeight: fontWeightVars['--font-weight-semibold'],
},
indicator: {
@@ -132,17 +150,12 @@ const styles = stylex.create({
transitionTimingFunction: easeVars['--ease-standard'],
},
indicatorSelected: {
- backgroundColor: colorVars['--color-accent'],
+ backgroundColor: colorVars['--color-icon-primary'],
opacity: 1,
},
indicatorUnselected: {
- backgroundColor: colorVars['--color-border'],
- opacity: {
- default: 0,
- [stylex.when.ancestor(':hover')]: {
- '@media (hover: hover)': 1,
- },
- },
+ backgroundColor: 'transparent',
+ opacity: 0,
},
icon: {
display: 'inline-flex',
@@ -172,6 +185,20 @@ const sizeStyles = stylex.create({
lg: {height: sizeVars['--size-element-lg']},
});
+// Hover bg uses the standard element size (one step smaller than tab)
+const hoverSizeStyles = stylex.create({
+ sm: {height: sizeVars['--size-element-sm']},
+ md: {height: sizeVars['--size-element-md']},
+ lg: {height: sizeVars['--size-element-lg']},
+});
+
+const layoutStyles = stylex.create({
+ fill: {
+ flex: 1,
+ justifyContent: 'center',
+ },
+});
+
const iconSizeStyles = stylex.create({
sm: {width: '14px', height: '14px'},
md: {width: '16px', height: '16px'},
@@ -206,6 +233,7 @@ export function XDSTab({
const isSelected = tabListCtx.value === value;
const size: XDSTabListSize = tabListCtx.size;
+ const isFill = tabListCtx.layout === 'fill';
const displayIcon = isSelected && selectedIcon ? selectedIcon : icon;
const handleSelect = useCallback(() => {
@@ -228,7 +256,8 @@ export function XDSTab({
styles.base,
sizeStyles[size],
isSelected && styles.selected,
- !isSelected && stylex.defaultMarker(),
+ isFill && layoutStyles.fill,
+ tabScope,
xstyle,
),
className,
@@ -236,6 +265,13 @@ export function XDSTab({
),
};
+ const hoverBgElement = (
+ <span
+ aria-hidden="true"
+ {...stylex.props(styles.hoverBg, hoverSizeStyles[size])}
+ />
+ );
+
const indicatorElement = (
<span
{...mergeProps(
@@ -262,6 +298,7 @@ export function XDSTab({
if (href != null) {
return (
<LinkComponent href={href} onClick={handleSelect} {...sharedProps}>
+ {hoverBgElement}
{iconElement}
{labelElement}
{indicatorElement}
@@ -271,6 +308,7 @@ export function XDSTab({
return (
<button type="button" onClick={handleSelect} {...sharedProps}>
+ {hoverBgElement}
{iconElement}
{labelElement}
{indicatorElement}
diff --git a/packages/core/src/TabList/XDSTabList.test.tsx b/packages/core/src/TabList/XDSTabList.test.tsx
index b06f085beb..d848ae7f33 100644
--- a/packages/core/src/TabList/XDSTabList.test.tsx
+++ b/packages/core/src/TabList/XDSTabList.test.tsx
@@ -300,7 +300,7 @@ describe('XDSTabMenu', () => {
).toBeInTheDocument();
});
- it('renders heading divider with menu label in dropdown', () => {
+ it('renders heading with menu label in dropdown', () => {
render(
<XDSTabList value="home" onChange={() => {}}>
<XDSTab value="home" label="Home" />
@@ -312,9 +312,9 @@ describe('XDSTabMenu', () => {
const menu = screen.getByRole('menu', {name: 'More', hidden: true});
expect(menu).toBeInTheDocument();
- // The heading is an XDSDivider with role="separator"
- const separator = screen.getByRole('separator', {hidden: true});
- expect(separator).toBeInTheDocument();
+ // The heading is a presentation span with the menu label
+ const heading = screen.getByRole('presentation', {hidden: true});
+ expect(heading).toHaveTextContent('More');
});
it('selects a menu item and calls onChange', async () => {
diff --git a/packages/core/src/TabList/XDSTabList.tsx b/packages/core/src/TabList/XDSTabList.tsx
index db55ac6562..cb7e79b9a9 100644
--- a/packages/core/src/TabList/XDSTabList.tsx
+++ b/packages/core/src/TabList/XDSTabList.tsx
@@ -34,6 +34,13 @@ export interface XDSTabListProps {
* @default 'md'
*/
size?: XDSTabListSize;
+ /**
+ * Layout mode for tab sizing.
+ * - `'hug'` (default): each tab hugs its content width.
+ * - `'fill'`: tabs stretch equally to fill the container width.
+ * @default 'hug'
+ */
+ layout?: 'hug' | 'fill';
/**
* Whether to show a bottom divider under the tab list.
* @default false
@@ -71,6 +78,9 @@ const styles = stylex.create({
alignItems: 'stretch',
gap: spacingVars['--spacing-0-5'],
},
+ fill: {
+ width: '100%',
+ },
divider: {
borderBottomWidth: borderVars['--border-width'],
borderBottomStyle: 'solid',
@@ -98,6 +108,7 @@ export function XDSTabList({
value,
onChange,
size = 'md',
+ layout = 'hug',
hasDivider = false,
xstyle,
className,
@@ -105,8 +116,8 @@ export function XDSTabList({
children,
}: XDSTabListProps) {
const contextValue = useMemo(
- () => ({value, onChange, size}),
- [value, onChange, size],
+ () => ({value, onChange, size, layout}),
+ [value, onChange, size, layout],
);
return (
@@ -115,7 +126,12 @@ export function XDSTabList({
aria-label="Tabs"
{...mergeProps(
xdsClassName('tab-list', {size}),
- stylex.props(styles.nav, hasDivider && styles.divider, xstyle),
+ stylex.props(
+ styles.nav,
+ layout === 'fill' && styles.fill,
+ hasDivider && styles.divider,
+ xstyle,
+ ),
className,
style,
)}>
diff --git a/packages/core/src/TabList/XDSTabListContext.ts b/packages/core/src/TabList/XDSTabListContext.ts
index 392ef0258d..4d9aa49d47 100644
--- a/packages/core/src/TabList/XDSTabListContext.ts
+++ b/packages/core/src/TabList/XDSTabListContext.ts
@@ -19,12 +19,20 @@ import {createContext, useContext} from 'react';
export type XDSTabListSize = 'sm' | 'md' | 'lg';
/**
- * Context for communicating value/onChange/size from XDSTabList to children.
+ * Layout mode for tab sizing.
+ * - `'hug'`: each tab hugs its content width.
+ * - `'fill'`: tabs stretch equally to fill the container width.
+ */
+export type XDSTabListLayout = 'hug' | 'fill';
+
+/**
+ * Context for communicating value/onChange/size/layout from XDSTabList to children.
*/
export interface XDSTabListContextValue {
value: string;
onChange: (value: string) => void;
size: XDSTabListSize;
+ layout: XDSTabListLayout;
}
export const XDSTabListContext = createContext<XDSTabListContextValue | null>(
diff --git a/packages/core/src/TabList/XDSTabMenu.tsx b/packages/core/src/TabList/XDSTabMenu.tsx
index 72089891c1..7040c6f832 100644
--- a/packages/core/src/TabList/XDSTabMenu.tsx
+++ b/packages/core/src/TabList/XDSTabMenu.tsx
@@ -28,9 +28,9 @@ import {
} from '../theme/tokens.stylex';
import {useXDSPopover} from '../Popover/useXDSPopover';
import {useListFocus} from '../hooks/useListFocus';
-import {XDSDivider} from '../Divider';
import {useXDSTabListContext} from './XDSTabListContext';
import type {XDSTabListSize} from './XDSTabListContext';
+import {tabScope} from './tab.markers.stylex';
import {xdsClassName, mergeProps} from '../utils';
export interface XDSTabMenuOption {
@@ -90,7 +90,7 @@ const styles = stylex.create({
},
},
triggerSelected: {
- color: colorVars['--color-text-accent'],
+ color: colorVars['--color-text-primary'],
fontWeight: fontWeightVars['--font-weight-semibold'],
},
triggerLabel: {
@@ -110,36 +110,38 @@ const styles = stylex.create({
pointerEvents: 'none',
fontWeight: fontWeightVars['--font-weight-semibold'],
},
- underline: {
- '::after': {
- content: '""',
- position: 'absolute',
- bottom: 0,
- left: 0,
- right: 0,
- height: '2px',
- backgroundColor: colorVars['--color-accent'],
- borderRadius: radiusVars['--radius-full'],
- },
- },
- hoverUnderline: {
+ indicator: {
position: 'absolute',
bottom: 0,
- left: 0,
- right: 0,
+ left: spacingVars['--spacing-3'],
+ right: spacingVars['--spacing-3'],
height: '2px',
- backgroundColor: colorVars['--color-border'],
borderRadius: radiusVars['--radius-full'],
- opacity: {
- default: 0,
- [stylex.when.ancestor(':hover')]: {
- '@media (hover: hover)': 1,
+ pointerEvents: 'none',
+ transitionProperty: 'opacity, background-color',
+ transitionDuration: durationVars['--duration-fast'],
+ transitionTimingFunction: easeVars['--ease-standard'],
+ },
+ indicatorSelected: {
+ backgroundColor: colorVars['--color-icon-primary'],
+ opacity: 1,
+ },
+ hoverBg: {
+ position: 'absolute',
+ inset: 0,
+ margin: 'auto',
+ width: '100%',
+ borderRadius: radiusVars['--radius-element'],
+ pointerEvents: 'none',
+ backgroundColor: {
+ default: 'transparent',
+ [stylex.when.ancestor(':hover', tabScope)]: {
+ '@media (hover: hover)': colorVars['--color-overlay-hover'],
},
},
- transitionProperty: 'opacity',
+ transitionProperty: 'background-color',
transitionDuration: durationVars['--duration-fast'],
transitionTimingFunction: easeVars['--ease-standard'],
- pointerEvents: 'none',
},
chevron: {
width: spacingVars['--spacing-4'],
@@ -158,7 +160,6 @@ const styles = stylex.create({
gap: spacingVars['--spacing-0-5'],
paddingBlock: spacingVars['--spacing-1'],
paddingInline: spacingVars['--spacing-1'],
- minWidth: '160px',
},
menuItem: {
display: 'flex',
@@ -202,6 +203,14 @@ const styles = stylex.create({
height: 16,
color: colorVars['--color-icon-primary'],
},
+ menuHeading: {
+ fontSize: typeScaleVars['--text-supporting-size'],
+ lineHeight: typeScaleVars['--text-supporting-leading'],
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ color: colorVars['--color-text-secondary'],
+ paddingBlock: spacingVars['--spacing-1'],
+ paddingInline: spacingVars['--spacing-3'],
+ },
});
const sizeStyles = stylex.create({
@@ -210,6 +219,13 @@ const sizeStyles = stylex.create({
lg: {height: sizeVars['--size-element-lg']},
});
+// Hover bg uses the standard element size (one step smaller than tab)
+const hoverSizeStyles = stylex.create({
+ sm: {height: sizeVars['--size-element-sm']},
+ md: {height: sizeVars['--size-element-md']},
+ lg: {height: sizeVars['--size-element-lg']},
+});
+
/**
* Tab menu trigger that opens a dropdown of additional tab options.
* Shows the selected option's label as trigger text when an option is active.
@@ -277,21 +293,18 @@ export function XDSTabMenu({label, options}: XDSTabMenuProps) {
styles.trigger,
sizeStyles[size],
hasSelectedOption && styles.triggerSelected,
- !hasSelectedOption && stylex.defaultMarker(),
+ tabScope,
),
)}>
<span
- {...stylex.props(
- styles.triggerLabel,
- hasSelectedOption && styles.underline,
- )}>
+ aria-hidden="true"
+ {...stylex.props(styles.hoverBg, hoverSizeStyles[size])}
+ />
+ <span {...stylex.props(styles.triggerLabel)}>
<span {...stylex.props(styles.triggerLabelText)}>{triggerLabel}</span>
<span aria-hidden="true" {...stylex.props(styles.triggerLabelSizer)}>
{triggerLabel}
</span>
- {!hasSelectedOption && (
- <span {...stylex.props(styles.hoverUnderline)} />
- )}
</span>
<span
aria-hidden="true"
@@ -301,6 +314,14 @@ export function XDSTabMenu({label, options}: XDSTabMenuProps) {
)}>
<XDSIcon icon="chevronDown" size="sm" color="inherit" />
</span>
+ {hasSelectedOption && (
+ <span
+ {...mergeProps(
+ xdsClassName('tab-indicator', {selected: 'selected'}),
+ stylex.props(styles.indicator, styles.indicatorSelected),
+ )}
+ />
+ )}
</button>
{popover.render(
<div
@@ -313,7 +334,9 @@ export function XDSTabMenu({label, options}: XDSTabMenuProps) {
xdsClassName('tab-menu-dropdown'),
stylex.props(styles.dropdown),
)}>
- <XDSDivider label={label} />
+ <span role="presentation" {...stylex.props(styles.menuHeading)}>
+ {label}
+ </span>
{options.map(option => {
const isSelected = tabListCtx.value === option.value;
return (
diff --git a/packages/core/src/TabList/tab.markers.stylex.ts b/packages/core/src/TabList/tab.markers.stylex.ts
new file mode 100644
index 0000000000..14cb746208
--- /dev/null
+++ b/packages/core/src/TabList/tab.markers.stylex.ts
@@ -0,0 +1,8 @@
+import * as stylex from '@stylexjs/stylex';
+
+/**
+ * Scoped marker for Tab ancestor selectors.
+ * Used by both XDSTab and XDSTabMenu to scope hover background styles
+ * and ensure they don't leak from parent containers.
+ */
+export const tabScope = stylex.defineMarker();