Skip to content

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

TypeScript

fix(tablist): reserve a gap under divided tabs so the hover pill clears the underline (#3913)

Ernest8475c0e323b4
diff --git a/.changeset/tablist-divider-indicator-gap.md b/.changeset/tablist-divider-indicator-gap.md
new file mode 100644
index 0000000000..24947db546
--- /dev/null
+++ b/.changeset/tablist-divider-indicator-gap.md
@@ -0,0 +1,9 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] TabList `hasDivider` reserves a gap so the hover pill and adjacent buttons no longer touch the underline
+
+A divided TabList now reserves 4px between the tabs and the divider rail. The hover highlight sits clear of the underline, and a same-size Button placed alongside the tabs aligns to the tab baseline instead of butting the rail — so a `md` tab strip pairs with a `md` button. The selected indicator still rests on the rail. Non-divided tab lists are unchanged. TabList inside a `Toolbar` with `dividers={['bottom']}` gets the same alignment via the toolbar's own spacing.
+
+@ernestt
diff --git a/apps/storybook/stories/TabList.stories.tsx b/apps/storybook/stories/TabList.stories.tsx
index e32c97cf1f..cfaf8e9351 100644
--- a/apps/storybook/stories/TabList.stories.tsx
+++ b/apps/storybook/stories/TabList.stories.tsx
@@ -213,14 +213,14 @@ export const WithActions: Story = {
<Button
label="Filter"
variant="ghost"
- size="sm"
+ size="lg"
icon={<FunnelIcon />}
isIconOnly
/>
<Button
label="New item"
variant="primary"
- size="sm"
+ size="lg"
icon={<PlusIcon />}
/>
</div>
@@ -229,6 +229,52 @@ export const WithActions: Story = {
},
};
+export const DividerGap: Story = {
+ name: 'Divider Gap (sm / md / lg)',
+ render: () => {
+ const [value, setValue] = useState('overview');
+ return (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '32px'}}>
+ {(['sm', 'md', 'lg'] as const).map(size => (
+ <div
+ key={size}
+ style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
+ <span style={{font: '600 12px system-ui', color: '#4E606F'}}>
+ size=&quot;{size}&quot; · hasDivider · matched Button size
+ </span>
+ <TabList value={value} onChange={setValue} size={size} hasDivider>
+ <Tab value="overview" label="Overview" />
+ <Tab value="activity" label="Activity" />
+ <Tab value="settings" label="Settings" />
+ <div
+ style={{
+ marginInlineStart: 'auto',
+ display: 'flex',
+ alignItems: 'center',
+ gap: '4px',
+ }}>
+ <Button
+ label="Filter"
+ variant="ghost"
+ size={size}
+ icon={<FunnelIcon />}
+ isIconOnly
+ />
+ <Button
+ label="New item"
+ variant="primary"
+ size={size}
+ icon={<PlusIcon />}
+ />
+ </div>
+ </TabList>
+ </div>
+ ))}
+ </div>
+ );
+ },
+};
+
export const FillLayout: Story = {
render: () => {
const [value, setValue] = useState('home');
diff --git a/packages/cli/templates/blocks/components/TabList/TabListTabsWithActions.doc.mjs b/packages/cli/templates/blocks/components/TabList/TabListTabsWithActions.doc.mjs
index 7dba8b939a..902d2d924b 100644
--- a/packages/cli/templates/blocks/components/TabList/TabListTabsWithActions.doc.mjs
+++ b/packages/cli/templates/blocks/components/TabList/TabListTabsWithActions.doc.mjs
@@ -7,7 +7,7 @@ export const doc = {
name: 'TabList — With Actions',
displayName: 'TabList — With Actions',
description:
- 'Page header pattern with tabs on the left and action buttons pushed to the right. When hasDivider is true, pair with a smaller button size (sm) so actions don\'t overpower the tab row.',
+ 'Page header pattern with tabs on the left and action buttons pushed to the right. When hasDivider is true, match the Button size to the TabList size so the tabs and actions align to a shared baseline above the divider.',
isReady: true,
aspectRatio: 4 / 3,
componentsUsed: ['TabList', 'Tab', 'Button'],
diff --git a/packages/cli/templates/blocks/components/TabList/TabListTabsWithActions.tsx b/packages/cli/templates/blocks/components/TabList/TabListTabsWithActions.tsx
index 491b26e3bd..a9558cf761 100644
--- a/packages/cli/templates/blocks/components/TabList/TabListTabsWithActions.tsx
+++ b/packages/cli/templates/blocks/components/TabList/TabListTabsWithActions.tsx
@@ -55,16 +55,11 @@ export default function TabListTabsWithActions() {
<Button
label="Filter"
variant="ghost"
- size="sm"
+ size="lg"
icon={FilterIcon}
isIconOnly
/>
- <Button
- label="New item"
- variant="primary"
- size="sm"
- icon={PlusIcon}
- />
+ <Button label="New item" variant="primary" size="lg" icon={PlusIcon} />
</div>
</TabList>
);
diff --git a/packages/core/src/TabList/Tab.tsx b/packages/core/src/TabList/Tab.tsx
index dcf4f118c8..6481f1b78e 100644
--- a/packages/core/src/TabList/Tab.tsx
+++ b/packages/core/src/TabList/Tab.tsx
@@ -138,7 +138,11 @@ const styles = stylex.create({
},
indicator: {
position: 'absolute',
- bottom: '-1px',
+ // Sits on the tab's bottom edge by default (-1px). When the tab strip
+ // reserves space for a divider rail — TabList `hasDivider` or a Toolbar
+ // with a bottom divider — that ancestor sets `--_tab-indicator-bottom`
+ // to drop the indicator onto the rail beneath the reserved gap.
+ bottom: 'var(--_tab-indicator-bottom, -1px)',
left: spacingVars['--spacing-3'],
right: spacingVars['--spacing-3'],
height: '2px',
diff --git a/packages/core/src/TabList/TabList.doc.mjs b/packages/core/src/TabList/TabList.doc.mjs
index 1a2c9cf504..5ec19969dd 100644
--- a/packages/core/src/TabList/TabList.doc.mjs
+++ b/packages/core/src/TabList/TabList.doc.mjs
@@ -92,7 +92,7 @@ export const docs = {
bestPractices: [
{ guidance: true, description: 'Keep tab labels short and descriptive so users can quickly scan available sections.' },
{ guidance: true, description: 'Use TabMenu to group overflow items when horizontal space is limited rather than scrolling tabs off-screen.' },
- { guidance: true, description: 'When using hasDivider with action buttons alongside tabs, use a smaller button size (sm) so the actions don\'t overpower the tab row.' },
+ { guidance: true, description: 'When using hasDivider with action buttons alongside tabs, match the Button size to the TabList size (both md, both sm) — the divided tab strip reserves space so tabs and same-size buttons align to a shared baseline above the rail.' },
{ guidance: false, description: 'Use tabs for sequential steps or workflows; use a stepper or wizard pattern instead.' },
{ guidance: false, description: 'Place more than 6–8 visible tabs before the overflow menu; prioritize the most important categories.' },
{ guidance: false, description: 'Confuse TabList with SegmentedControl or ToggleButton. TabList is for navigation between views. SegmentedControl and ToggleButton are input controls: SegmentedControl always has exactly one selected option, while ToggleButton can be toggled on or off.' },
@@ -113,7 +113,7 @@ export const docsZh = {
bestPractices: [
{ guidance: true, description: 'Keep tab labels short and descriptive so users can quickly scan available sections.' },
{ guidance: true, description: 'Use TabMenu to group overflow items when horizontal space is limited rather than scrolling tabs off-screen.' },
- { guidance: true, description: 'When using hasDivider with action buttons alongside tabs, use a smaller button size (sm) so the actions don\'t overpower the tab row.' },
+ { guidance: true, description: 'When using hasDivider with action buttons alongside tabs, match the Button size to the TabList size (both md, both sm) — the divided tab strip reserves space so tabs and same-size buttons align to a shared baseline above the rail.' },
{ guidance: false, description: 'Use tabs for sequential steps or workflows; use a stepper or wizard pattern instead.' },
{ guidance: false, description: 'Place more than 6–8 visible tabs before the overflow menu; prioritize the most important categories.' },
{ guidance: false, description: 'Confuse TabList with SegmentedControl or ToggleButton. TabList is for navigation between views. SegmentedControl and ToggleButton are input controls: SegmentedControl always has exactly one selected option, while ToggleButton can be toggled on or off.' },
@@ -135,7 +135,7 @@ export const docsDense = {
bestPractices: [
{ guidance: true, description: 'Keep tab labels short and descriptive so users can quickly scan available sections.' },
{ guidance: true, description: 'Use TabMenu to group overflow items when horizontal space is limited rather than scrolling tabs off-screen.' },
- { guidance: true, description: 'When using hasDivider with action buttons alongside tabs, use a smaller button size (sm) so the actions don\'t overpower the tab row.' },
+ { guidance: true, description: 'When using hasDivider with action buttons alongside tabs, match the Button size to the TabList size (both md, both sm) — the divided tab strip reserves space so tabs and same-size buttons align to a shared baseline above the rail.' },
{ guidance: false, description: 'Use tabs for sequential steps or workflows; use a stepper or wizard pattern instead.' },
{ guidance: false, description: 'Place more than 6–8 visible tabs before the overflow menu; prioritize the most important categories.' },
{ guidance: false, description: 'Confuse TabList with SegmentedControl or ToggleButton. TabList is for navigation between views. SegmentedControl and ToggleButton are input controls: SegmentedControl always has exactly one selected option, while ToggleButton can be toggled on or off.' },
diff --git a/packages/core/src/TabList/TabList.test.tsx b/packages/core/src/TabList/TabList.test.tsx
index d26e3b9b39..e7536998df 100644
--- a/packages/core/src/TabList/TabList.test.tsx
+++ b/packages/core/src/TabList/TabList.test.tsx
@@ -323,6 +323,72 @@ describe('TabList', () => {
});
});
+describe('TabList divider gap', () => {
+ // The divider adds the reserved gap + indicator offset via a single class
+ // (StyleX applies deterministic classes in the test env). Capture that
+ // class set once so the assertions describe intent, not opaque hashes.
+ function navClasses(hasDivider: boolean): Set<string> {
+ const {unmount} = render(
+ <TabList value="home" onChange={() => {}} hasDivider={hasDivider}>
+ <Tab value="home" label="Home" />
+ </TabList>,
+ );
+ const nav = screen.getByRole('navigation');
+ const classes = new Set(nav.className.split(/\s+/).filter(Boolean));
+ unmount();
+ return classes;
+ }
+
+ it('adds divider-only styling classes when hasDivider is set', () => {
+ const withDivider = navClasses(true);
+ const withoutDivider = navClasses(false);
+
+ // Every class the plain nav has must still be present when divided: the
+ // divider only adds styling (border + reserved gap + indicator offset),
+ // it never removes the base nav styles.
+ for (const cls of withoutDivider) {
+ expect(withDivider.has(cls)).toBe(true);
+ }
+
+ // And it must add at least one class the undivided nav does not have.
+ const added = [...withDivider].filter(c => !withoutDivider.has(c));
+ expect(added.length).toBeGreaterThan(0);
+ });
+
+ it('does not add divider styling to an undivided tab list (default)', () => {
+ // Default (no hasDivider) and explicit hasDivider={false} are identical:
+ // the non-divided path is untouched by the divider gap change.
+ expect(navClasses(false)).toEqual(
+ (() => {
+ const {unmount} = render(
+ <TabList value="home" onChange={() => {}}>
+ <Tab value="home" label="Home" />
+ </TabList>,
+ );
+ const nav = screen.getByRole('navigation');
+ const classes = new Set(nav.className.split(/\s+/).filter(Boolean));
+ unmount();
+ return classes;
+ })(),
+ );
+ });
+
+ it('keeps the selected indicator rendered under a divider', () => {
+ render(
+ <TabList value="home" onChange={() => {}} hasDivider>
+ <Tab value="home" label="Home" />
+ <Tab value="away" label="Away" />
+ </TabList>,
+ );
+ const selected = screen.getByRole('button', {name: 'Home'});
+ // The indicator span carries the selected marker; the divider must not
+ // drop it (it is repositioned onto the rail, not removed).
+ expect(
+ selected.querySelector('[data-selected="selected"]'),
+ ).toBeInTheDocument();
+ });
+});
+
describe('TabList keyboard navigation (roving tabindex)', () => {
it('exposes the tab strip as a single Tab stop (only selected tab is tabbable)', () => {
render(
diff --git a/packages/core/src/TabList/TabList.tsx b/packages/core/src/TabList/TabList.tsx
index 2d459ace15..5dd0941c67 100644
--- a/packages/core/src/TabList/TabList.tsx
+++ b/packages/core/src/TabList/TabList.tsx
@@ -96,6 +96,14 @@ const styles = stylex.create({
borderBottomWidth: borderVars['--border-width'],
borderBottomStyle: 'solid',
borderBottomColor: colorVars['--color-border'],
+ // Reserve a gap between the tabs and the divider rail so the hover pill
+ // (which fills the tab height) no longer touches the underline, and an
+ // adjacent same-size Button aligns to the tabs rather than butting the
+ // rail. The tabs keep their element-size height; this padding grows the
+ // strip. `--_tab-indicator-bottom` drops the selected indicator through
+ // the reserved gap (+ the 1px border) so it still sits on the rail.
+ paddingBlockEnd: spacingVars['--spacing-1'],
+ '--_tab-indicator-bottom': `calc(-1 * (${spacingVars['--spacing-1']} + ${borderVars['--border-width']}))`,
},
});
diff --git a/packages/core/src/TabList/TabMenu.tsx b/packages/core/src/TabList/TabMenu.tsx
index 41fec70772..9cbb0f1685 100644
--- a/packages/core/src/TabList/TabMenu.tsx
+++ b/packages/core/src/TabList/TabMenu.tsx
@@ -122,7 +122,10 @@ const styles = stylex.create({
},
indicator: {
position: 'absolute',
- bottom: '-1px',
+ // Mirrors Tab's indicator: sits on the bottom edge by default (-1px), or
+ // drops onto the divider rail when an ancestor (TabList `hasDivider` or a
+ // Toolbar with a bottom divider) sets `--_tab-indicator-bottom`.
+ bottom: 'var(--_tab-indicator-bottom, -1px)',
left: spacingVars['--spacing-3'],
right: spacingVars['--spacing-3'],
height: '2px',
diff --git a/packages/core/src/Toolbar/Toolbar.tsx b/packages/core/src/Toolbar/Toolbar.tsx
index c62d2e82fd..0794edabda 100644
--- a/packages/core/src/Toolbar/Toolbar.tsx
+++ b/packages/core/src/Toolbar/Toolbar.tsx
@@ -239,6 +239,7 @@ export function Toolbar({
const hasCenterContent = centerContent != null;
const hasStartContent = startContent != null;
const hasEndContent = endContent != null;
+ const hasBottomDivider = dividers?.includes('bottom') ?? false;
const gapVar = spacingVars[spacingStepToVar[gap]] as string;
@@ -316,9 +317,15 @@ export function Toolbar({
orientation === 'vertical' && styles.vertical,
sizeStyles.base,
dynamicStyles.gap(gapVar),
- dynamicStyles.tabIndicatorBottom(
- `calc(-1 * (${blockPaddingVarForSize[size]}${dividers?.includes('bottom') ? ' + 1px' : ''}))`,
- ),
+ // Only drop the tab indicator through the toolbar's block padding
+ // onto the rail when a bottom divider is actually present.
+ // Without a divider, leave `--_tab-indicator-bottom` unset so a
+ // nested TabList's indicator keeps its own default (hugging the
+ // tab) instead of floating down into the toolbar's padding.
+ hasBottomDivider &&
+ dynamicStyles.tabIndicatorBottom(
+ `calc(-1 * (${blockPaddingVarForSize[size]} + 1px))`,
+ ),
),
)}
{...props}>