RailTabs
Vertical icon tabs on the outer edge of a side panel that switch its panes (Xcode’s inspector, Zendesk’s context bar): each tab is an icon plus a two- or three-character short name, with the full name as its tooltip. Controlled value + onChange; a null value means the panel is collapsed, and with collapsible pressing the current tab collapses it.
Status: experimental · Components: RailTabs, TouchNavigationBar, TouchTabBar
Import
Section titled “Import”import { RailTabs, TouchNavigationBar, TouchTabBar } from 'nacre'Put it in a 60-wide column (each tab is 52 × 46); with collapsible, pressing the current tab calls onChange(null) and the rail stays with no current tab. icon is an icon name or the app’s own SVG asset (tinted by token).
import { Text, View, signal } from 'nsh'import { RailTabs, Swap, TEXT_SIZE } from 'nacre'import type { RailTabItem } from 'nacre'
type Panel = 'member' | 'copilot' | 'note' | 'quickReply'
const panels = (): RailTabItem<Panel>[] => [ { value: 'member', label: 'Customer info', shortLabel: 'Info', icon: 'user' }, { value: 'copilot', label: 'AI answers', shortLabel: 'AI', icon: 'sparkles' }, { value: 'note', label: 'Service notes', shortLabel: 'Notes', icon: 'pencil' }, { value: 'quickReply', label: 'Quick replies', shortLabel: 'Replies', icon: 'zap' },]
export function RailTabsUsage() { const panel = signal<Panel | null>('member') const current = () => panels().find((p) => p.value === panel()) return ( <View class="flex-row w-[440px] max-w-full h-[240px] rounded-lg border border-border overflow-hidden"> <View class="flex-1 p-3 bg-card"> <Text class={`${TEXT_SIZE.small} text-muted-foreground`}>Conversation</Text> </View> {/* 面板开合:RailTabs 在收起 / 打开前自己配好布局动画,面板宽度 0 ↔ 180 顺滑过去;面板之间切换用 Swap 换内容 */} <If when={current()}> {(item) => ( <View testID="rail-tabs-usage-panel" class="w-[180px] p-3 border-l border-border bg-card overflow-hidden"> <Swap value={item().value}> <Text testID="rail-tabs-usage-current" class="text-body font-medium text-foreground">{item().label}</Text> </Swap> </View> )} </If> <View class="w-[60px] items-center py-2 border-l border-border bg-background"> <RailTabs testID="rail-tabs-usage" accessibilityLabel="Panels" items={panels()} value={panel()} onChange={(value) => panel.set(value)} collapsible /> </View> </View> )}Examples
Section titled “Examples”Bottom navigation on a phone
Section titled “Bottom navigation on a phone”Control the selected tab with value. Tapping a tab changes the page and updates the navigation title.
import { View, signal } from 'nsh'import { TouchNavigationBar, TouchTabBar, hairlineBottom } from 'nacre'
export function RailTabsTouchNavigation() { const tabs = () => [ { value: 'chats', label: 'Chats', icon: 'chat' as const }, { value: 'me', label: 'Me', icon: 'user' as const }, ] const page = signal('chats') // 一块缩小的手机屏:导航栏、内容区(plane)、底部标签栏,导航与标签栏同用 background 底 return <View class="mx-4 rounded-xl overflow-hidden bg-background border border-border"> <View class={hairlineBottom()}><TouchNavigationBar title={tabs().find((t) => t.value === page())!.label} /></View> <View class="h-24 bg-plane" /> <TouchTabBar testID="demo-touch-tabs" tabs={tabs()} value={page()} onChange={(v) => page.set(v)} /> </View>}Not collapsible, and in a row
Section titled “Not collapsible, and in a row”Without collapsible, pressing the current tab does nothing; orientation=“horizontal” lays the tabs in a row and the arrow keys become ← →.
import { View, signal } from 'nsh'import { RailTabs } from 'nacre'import type { RailTabItem } from 'nacre'
type Panel = 'member' | 'copilot' | 'note' | 'quickReply'
const panels = (): RailTabItem<Panel>[] => [ { value: 'member', label: 'Customer info', shortLabel: 'Info', icon: 'user' }, { value: 'copilot', label: 'AI answers', shortLabel: 'AI', icon: 'sparkles' }, { value: 'note', label: 'Service notes', shortLabel: 'Notes', icon: 'pencil' }, { value: 'quickReply', label: 'Quick replies', shortLabel: 'Replies', icon: 'zap' },]
export function RailTabsFixed() { const panel = signal<Panel | null>('copilot') return ( <View class="flex-row flex-wrap items-start gap-6"> <RailTabs testID="rail-tabs-fixed" accessibilityLabel="Panels (always open)" items={panels()} value={panel()} onChange={(value) => panel.set(value)} /> <RailTabs testID="rail-tabs-row" orientation="horizontal" accessibilityLabel="Panels (row)" items={panels()} value={panel()} onChange={(value) => panel.set(value)} /> </View> )}Keyboard
Section titled “Keyboard”| Key | Action |
|---|---|
| Tab | The group is one Tab stop: entering lands on the current tab (the first when collapsed), pressing again leaves the group |
| ↑ ↓(横排 ← →) | Switch to the adjacent pane, wrapping at the ends. After a click, arrow keys continue from the clicked tab. |
| Home / End | Go to the first / last tab and switch to it |
| Space / Return | Press the focused tab: switch to it; with collapsible, the current tab collapses the panel |
Accessibility
Section titled “Accessibility”- The group is a tab list (nsh/base Tabs, tablist + orientation) and the current tab is read as selected; while the panel is collapsed no tab is selected. accessibilityLabel says what the group switches (“Panels”).
- Each tab’s screen reader name and tooltip are its label (the full name); the short name is visual only and the icon is decorative.
- The current tab gets the selected fill, an accent-colored icon and foreground text, without changing weight, so it never relies on fill alone.
Do / Don’t
Section titled “Do / Don’t”Do
- Keep short names to two or three characters (one word in English or Japanese) and put the full name in label
- Pass collapsible when the panel can collapse
- Use itemTestID when the tabs already have test IDs
Don’t
- Use it as the app’s main navigation (use Sidebar)
- Switch views within one area (use Segmented tabs)
- Show icons without short names
Property descriptions follow the Chinese source comments.
RailTabs
Section titled “RailTabs”| Prop | Type | Default | Description |
|---|---|---|---|
items * |
readonly RailTabItem<T>[] |
— | 各项,按显示顺序;增减项(会话里多出「上下文」)时当前值由调用方决定落到哪一项 |
value * |
T | null |
— | 当前打开的面板;null 表示面板收起(没有选中项,栏本身仍在) |
onChange * |
(value: T | null) => void |
— | 选中另一项时给它的值;collapsible 时再点当前项给 null |
collapsible |
boolean |
— | 再点当前项收起面板(Xcode 检查器、VS Code 活动栏同样);默认 false:再点不变 |
orientation |
'vertical' | 'horizontal' |
'vertical' |
默认 vertical(↑↓ 走);horizontal 时排成一行、←→ 走 |
accessibilityLabel |
string |
— | 整组的读屏名(「面板」) |
testID |
string |
— | 整组的 testID;每项默认 ${testID}-${value} |
itemTestID |
(value: T) => string |
— | 每项的 testID,给了就不用默认规则(兼容应用里已有的 testID) |
* required
TouchNavigationBar
Section titled “TouchNavigationBar”| Prop | Type | Default | Description |
|---|---|---|---|
title * |
string |
— | |
left |
TouchNavigationAction |
— | |
right |
TouchNavigationAction |
— | |
testID |
string |
— |
* required
TouchTabBar
Section titled “TouchTabBar”| Prop | Type | Default | Description |
|---|---|---|---|
value * |
V |
— | |
tabs * |
readonly TouchTab<V>[] |
— | |
onChange * |
(value: V) => void |
— | |
testID |
string |
— |
* required