ナビゲーション · 準拠済み
Tabs
TabsTabItemTabsPropsTabsVariant
Tabs
Roving-focus tabs with a sliding indicator, icon+label rows, and panels switched in place.
Your photo library.
Your home feed.
import { Icon, Surface, Tabs, Text } from '@language-lit/material3-expressive'
export function TabsExample() {
return (
<Surface
as="section"
aria-labelledby="tabs-example-title"
color="surface-container-low"
shape="extra-large"
className="tabs-example"
>
<Text as="h2" id="tabs-example-title" variant="titleLarge" emphasis="emphasized">
Tabs
</Text>
<Text as="p" variant="bodyMedium">
Roving-focus tabs with a sliding indicator, icon+label rows, and
panels switched in place.
</Text>
<Tabs
aria-label="Library sections"
items={[
{
value: 'photos',
label: 'Photos',
icon: <Icon source="photo" />,
panel: <Text as="p" variant="bodyMedium">Your photo library.</Text>,
},
{
value: 'shared',
label: 'Shared',
icon: <Icon source="folder_shared" />,
panel: <Text as="p" variant="bodyMedium">Albums shared with you.</Text>,
},
{
value: 'trash',
label: 'Trash',
icon: <Icon source="delete" />,
disabled: true,
panel: <Text as="p" variant="bodyMedium">Recently deleted items.</Text>,
},
]}
/>
<Tabs
aria-label="Secondary section"
variant="secondary"
defaultValue="overview"
items={[
{ value: 'overview', label: 'Overview' },
{ value: 'activity', label: 'Activity' },
{ value: 'settings', label: 'Settings' },
{ value: 'archived', label: 'Archived', disabled: true },
]}
/>
<Tabs
aria-label="Scrollable section"
scrollable
items={[
{
value: 'home',
label: 'Home',
icon: <Icon source="home" />,
panel: <Text as="p" variant="bodyMedium">Your home feed.</Text>,
},
{
value: 'explore',
label: 'Explore',
icon: <Icon source="explore" />,
panel: <Text as="p" variant="bodyMedium">Discover new content.</Text>,
},
{
value: 'notifications',
icon: <Icon source="notifications" />,
panel: <Text as="p" variant="bodyMedium">Icon-only tab: no label, just an icon.</Text>,
},
{
value: 'messages',
label: 'Messages',
icon: <Icon source="mail" />,
panel: <Text as="p" variant="bodyMedium">Your conversations.</Text>,
},
{
value: 'favorites',
label: 'Favorites',
icon: <Icon source="star" />,
panel: <Text as="p" variant="bodyMedium">Items you starred.</Text>,
},
{
value: 'downloads',
label: 'Downloads',
icon: <Icon source="download" />,
href: '#downloads',
},
{
value: 'archive',
label: 'Archive',
icon: <Icon source="archive" />,
panel: <Text as="p" variant="bodyMedium">Archived items.</Text>,
},
{
value: 'settings-2',
label: 'Settings',
icon: <Icon source="settings" />,
panel: <Text as="p" variant="bodyMedium">App preferences.</Text>,
},
]}
/>
</Surface>
)
}Tabsは、フォーカスを順送りするrole="tablist"とスライドする選択インジケーターを表示します。データ駆動型のため、内容、パネル、リンクによるナビゲーションタブもすべてitemsで定義します。
import { Icon, Tabs } from '@language-lit/material3-expressive'
import '@language-lit/material3-expressive/styles.css'
<Tabs
aria-label="Library sections"
items={[
{ value: 'photos', label: 'Photos', icon: <Icon source="photo" />, panel: <PhotoGrid /> },
{ value: 'shared', label: 'Shared', icon: <Icon source="folder_shared" />, panel: <SharedList /> },
]}
/>仕様
items: readonly TabItem[]でタブリストの内容を指定します。形式は{ value, label?, icon?, disabled?, href?, panel? }です。role="tablist"領域の名前としてaria-labelまたはaria-labelledbyが必須です。これはグループロールを持つほかのコンポーネントと同じ命名要件です。value/defaultValue/onValueChangeは、ほかの状態を持つコンポーネントと同じ制御/非制御の形式です。defaultValueを省略すると最初の項目の値が使われます。variantの既定値は'primary'です。短く丸いインジケーターが選択タブのコンテンツ幅に沿って表示され、primaryで色付けされます。'secondary'では全幅の下線になり、ブランドカラーではなく通常のonSurfaceで色付けされます。こちらは意図的に控えめな表示です。scrollable(既定値false)を指定すると、均等配置の固定行から横スクロール可能な行に切り替わります。スクロール範囲内に収まる場合、選択中のタブを中央に保ちます。これはソースのScrollableTabRowが独自のスクロール状態で行う動作と同じです。スクロールするのはタブ行だけで、選択時に祖先のスクロールコンテナーは移動しません。
リンク対応のナビゲーションタブ
href付きの項目は<button role="tab">ではなく<a role="tab" href>をレンダーします。矢印キーでローカルの選択とインジケーターの状態は更新されますが、実際のナビゲーションはブラウザー標準のアンカー動作に完全に任せます。キー入力を受けてTabsがナビゲーションを合成することはありません。これによりルーターの現在のルートを使ってTabsを制御できます。
<Tabs
aria-label="Settings"
value={router.pathname}
items={[
{ value: '/settings/profile', label: 'Profile', href: '/settings/profile' },
{ value: '/settings/billing', label: 'Billing', href: '/settings/billing' },
]}
/>パネル
panelを持つ項目については、選択中の項目だけにrole="tabpanel"領域を1つ表示し、id/aria-controls/aria-labelledbyで正しく関連付けます。リンクのみの用途など、どの項目にもpanelがない場合は、tabpanel領域を出力しません。
キーボード操作
| キー | 動作 |
|---|---|
| ArrowLeft / ArrowRight | フォーカスと選択を移動し、無効なタブを飛ばして循環 |
| Home / End | 有効な最初/最後のタブに移動して選択 |
トークンと境界
色、形状、モーションの値は--m3e-comp-tabs-*の1つの登録にまとめられています。テーマの上書きはMaterial3Providerのスコープ内で適用されます。Tabsは実行時スタイルを注入せず、Next.js、Vite、ルーター、アニメーションライブラリ、非公開のアプリケーションコードをインポートしません。