Skip to content

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

TypeScript

docs(Tab): underline the whole selected tab with a nested Theme (#10814)

Cindy Zhang09710569f387
diff --git a/.changeset/tab-full-width-indicator-recipe.md b/.changeset/tab-full-width-indicator-recipe.md
new file mode 100644
index 0000000000..37b82ca489
--- /dev/null
+++ b/.changeset/tab-full-width-indicator-recipe.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[docs] Tab's docs show how to run the selected indicator edge to edge in one strip: a nested `Theme` that takes the app's color mode, extends the app's theme and sets `insetInline: '0'` on the `tab-indicator` target, so other TabLists keep the default indicator. The override is best effort across releases.
+
+@cixzhang
diff --git a/apps/storybook/stories/TabList.stories.tsx b/apps/storybook/stories/TabList.stories.tsx
index c15bd5c535..32da973842 100644
--- a/apps/storybook/stories/TabList.stories.tsx
+++ b/apps/storybook/stories/TabList.stories.tsx
@@ -13,6 +13,8 @@ import {
import {Heading} from '@astryxdesign/core/Text';
import {Icon} from '@astryxdesign/core/Icon';
import {Tooltip} from '@astryxdesign/core/Tooltip';
+import {Theme, defineTheme, useTheme} from '@astryxdesign/core/theme';
+import {neutralTheme} from '@astryxdesign/theme-neutral';
import {
PlusIcon,
FunnelIcon,
@@ -1117,6 +1119,56 @@ export const DescribedTabs: Story = {
},
};
+/**
+ * An editor-style strip that runs the selected indicator edge to edge. A
+ * nested Theme restyles the `tab-indicator` target, so only this strip
+ * changes; it takes the outer color mode. `insetInline` is not a guaranteed
+ * property of that target, so the override is best effort across releases.
+ */
+const fullWidthIndicatorTheme = defineTheme({
+ name: 'full-width-tab-indicator',
+ extends: neutralTheme,
+ components: {
+ 'tab-indicator': {
+ base: {insetInline: '0'},
+ },
+ },
+});
+
+export const FullWidthIndicator: Story = {
+ name: 'Full-Width Indicator (Nested Theme)',
+ render: () => {
+ const [value, setValue] = useState('app');
+ const {mode} = useTheme();
+ return (
+ <VStack gap={4}>
+ <Theme theme={fullWidthIndicatorTheme} mode={mode}>
+ <TabList
+ value={value}
+ onChange={setValue}
+ aria-label="Open files"
+ size="sm"
+ hasDivider>
+ <Tab value="app" label="App.tsx" />
+ <Tab value="styles" label="styles.css" />
+ <Tab value="readme" label="README.md" />
+ </TabList>
+ </Theme>
+ <TabList
+ value={value}
+ onChange={setValue}
+ aria-label="Default indicator, for comparison"
+ size="sm"
+ hasDivider>
+ <Tab value="app" label="App.tsx" />
+ <Tab value="styles" label="styles.css" />
+ <Tab value="readme" label="README.md" />
+ </TabList>
+ </VStack>
+ );
+ },
+};
+
export const PressedState: Story = {
name: 'Pressed state',
parameters: {
diff --git a/packages/core/src/TabList/Tab.doc.mjs b/packages/core/src/TabList/Tab.doc.mjs
index 4e122b6d1e..482f75596a 100644
--- a/packages/core/src/TabList/Tab.doc.mjs
+++ b/packages/core/src/TabList/Tab.doc.mjs
@@ -15,6 +15,42 @@ export const docs = {
wrapper: {component: 'TabList', props: {value: 'tab-1'}},
},
examples: [
+ {
+ label: 'Underline the whole tab in one strip',
+ code: `import {Tab, TabList} from '@astryxdesign/core/TabList';
+import {Theme, defineTheme, useTheme} from '@astryxdesign/core/theme';
+import {appTheme} from './theme';
+
+// Without a nested Theme, the selected indicator spans the tab's content and
+// stops at its inline padding. An editor-style strip can run it edge to edge by restyling
+// the tab-indicator target in a nested Theme. Only this strip changes: every
+// other TabList keeps the app theme's indicator. insetInline is not a
+// guaranteed property of the tab-indicator target, so treat this override as
+// best effort across releases.
+const fullWidthIndicatorTheme = defineTheme({
+ name: 'full-width-tab-indicator',
+ extends: appTheme,
+ components: {
+ 'tab-indicator': {
+ base: {insetInline: '0'},
+ },
+ },
+});
+
+// An open-files bar switches views, so it uses TabList's navigation pattern
+// (no role="tablist"). The nested Theme takes the app's color mode.
+function EditorTabs() {
+ const {mode} = useTheme();
+ return (
+ <Theme theme={fullWidthIndicatorTheme} mode={mode}>
+ <TabList value="app" onChange={() => {}} aria-label="Open files" size="sm" hasDivider>
+ <Tab value="app" label="App.tsx" />
+ <Tab value="styles" label="styles.css" />
+ </TabList>
+ </Theme>
+ );
+}`,
+ },
{
label: 'Describe a tab with help text',
code: `import {useRef, useState} from 'react';