Raft 设计系统

组件 · 导航

Tab

一个对象在一格的 TabBar 里的标签页:它的图标和标题、它的 ×,以及像浏览器标签页那样打开的菜单;固定、只剩标题、新东西、等待登录、任务的写法和网页的标题。

实验性也叫 Object tab, Workspace tab, Editor tab, Browser tab
import { Tab } from "@botiverse/raft-ui/wip";

Tab 是开在一格里的一个对象,放在这一格的 TabBar 里:它说明对象是什么,即图标和标题,不放对象的任何动作。前面那个标签页的 × 一直显示;后面的标签页的 × 悬停时才出现。和浏览器一样,标签页菜单没有按钮:右键、触屏按住再抬手、Shift+F10 或菜单键打开它。它建在 TabsTab 上,所以整个标签栏是一个 tablist,带漫游焦点和方向键(标签页与分栏)。

tab/compositions/preview

何时使用

场景使用
开在对话旁边一格里的对象:文档、任务、文件、App、网页Tab,放在 TabBar 里
同一页面的各个部分,每个部分有自己的内容Tabs
同一内容的另一种视图SegmentedControl
从要一条条处理的列表里打开的东西不是标签页:开在旁边那一格(标签页与分栏)

结构

  • 标签页:一个 TabsTab,名字是标签页的完整名字(tabAccessibleName),里面有:
    • 图标(16px),由 icon 给出;
    • 标题:对象是 prefix 和 title;site 是它的 pageTitle,还没有标题时是 SiteDomain 画的域名,http 时前面有「不安全」;
    • 新东西,以及等待登录时的钥匙。
  • 它的 ×,叠在标签页末端,不在 Tab 顺序里。
  • 标签页菜单:menu,ContextMenu 的菜单项。

状态

状态属性显示什么
在前面TabBar 的 value选中的贴纸;× 一直显示。宽度和在后面时一样。
在后面悬停时显示 ×。
固定pinned排在最前、只剩图标、图标居中、没有 ×。读作「…,已固定」。工作区的标签页眼下不用它。
新东西unread、unreadDot数得清的用未读数(Badge,accent);数不清的用提醒点(Status,accent)。
等待登录waitingSignIn标题后面一把钥匙,直到标签页显示出来:后台的页面从不自己完成登录。
只剩标题TabBar 的 density="compact"不到 280px 的一格里,每个标签页不管在不在前面都只剩标题,没有图标;× 叠在标题末端。
拖动中dragging、shift原位留着、透明度 40%(data-drag-origin);放下点之后的标签页让开 TAB_DROP_GAP。
被挤掉的squeezed标签栏那一格最大化时别的格的标签页,跟在分隔线后面,变淡:没有 ×,从不到前面;菜单照样能打开。
并入的TabBar merged窄窗口里并进标签栏的那一列的标签页,跟在分隔线后面:完整的标签页,和标签栏自己的一样(data-merged)。
再次打开located定位高亮,一次(状态)。
tab/compositions/title-only
tab/compositions/dragging

行为

  • source 说明标题和图标从哪里来:app 是 App 注册的名字和图标;site 是一个网页;object 是 App 自己的对象。和浏览器一样,网页的标签页用页面标题(pageTitle)命名,前面后面的标签页都一样;只有页面还没有标题时,标签页才显示它的域名(title)。完整网址从不出现在标签页上:它在地址行里。
  • 标题和图标从对象实时取,所以对象改名或任务换状态会立刻显示出来。
  • 任务的标签页是它的写法加标题。标签页变窄时位置先让(#launch-week:、dm:@Martin:),编号和标题的开头一直在;被挤成残段的位置直接去掉。
tab/compositions/task-reference
  • 页面还没有标题时显示的域名由 SiteDomain 画,从开头截,从不截结尾;页面标题和其他标题一样从结尾截。http 时,「不安全」放在标签页显示的内容前面;只剩标题的标签页(compact 的标签栏)把它留给地址行。
tab/compositions/site
  • 和浏览器标签页的菜单一样,任何标签页的菜单都没有按钮。打开方式:右键(开在指针那里)、Shift+F10 或菜单键(开在标签页下面,第一项高亮),以及触屏按住 500ms 不动再抬手(开在标签页下面)。按住后移动是拖动;手指没抬起时菜单从不打开,这一点和其他带菜单的项不同(状态)。菜单关上后焦点回到标签页,除非 menuHandsFocus 说选中的项把焦点交给了别处。
  • onClose 收到标签页的 value:×、有焦点时按 Delete 或 Backspace,以及中键点击。固定的和被挤掉的标签页不能关;并入的和标签栏里任何标签页一样能关。
  • 和浏览器一样,选中一个标签页从不改变任何宽度,它自己的和别的都不变:标签页在不在前面排法都一样。显示的东西一样,不管 × 显不显示都留着 × 的位置(后面的标签页悬停时 × 出现在这个位置),前面那个的字重和其他的一样;变的只有颜色。
  • 前面那个标签页总留在标签栏里:宽度规则从不把它收起来,也从不另给它一个宽度。
  • pinned 留着等以后再定:工作区的标签页眼下没有固定,所以外壳从不传它(标签页与分栏)。
  • 每个标签页的宽度、哪个在前面(它的 value)、显示多少(它的 density)都由 TabBar 决定;Tab 自己最宽只到上限(200px,只剩标题时 120px)。

内容

  • 标题是对象自己的:文档或任务的标题、App 注册的名字、网页的标题。网站的主机名照 URL.host 给出的样子作为 title 传入:只在页面还没有标题时显示。
  • 任务的写法照 App 的写法:#launch-week:#25、dm:@Martin:#3。
  • 译文通过 messages 传入;默认是英文(UI 文案)。

无障碍

  • 每个标签页是标签栏 tablist 里的一个 role="tab"(Tabs);它的无障碍名称和提示是它显示的内容加上状态:「#launch-week:#25 Ship the tab bar, 2 new」「Example Docs, pinned」(页面的标题;还没有标题时是域名)、「Board, waiting to sign in」。
  • ← 和 → 在标签页之间移动,Enter 或空格把它放到前面,Delete 或 Backspace 关掉它,Shift+F10 或菜单键打开它的菜单。× 不在 Tab 顺序里:键盘通过标签页本身用到它(Delete)。
  • 关掉有焦点的标签页会移除它:由 App 把焦点移到到了前面的那个标签页。
  • × 名叫 Close 加标签页的名字。菜单以标签页命名。
  • 未读数、提醒点和钥匙对辅助技术隐藏:标签页的名字已经说出它们。
  • 标签栏自己没有 tab panel。要把标签页和它显示的内容连起来,给 Tab 一个 id 和 aria-controls,给那一格的 PaneBody 加 role="tabpanel"、作为 aria-controls 指向的目标,并用 aria-labelledby 指向标签页的 id(Pane)。Tab 把 id、aria-controls 和 aria-describedby 放在它的 role="tab" 元素上;其他属性放在外层。

规则

  • 标签页上只放对象的图标和标题:对象的动作放在它那一行的 ⋯ 里,网页和 App 的也一样。标签页菜单只放标签页和这一格的动作。
  • 不给任何标签页放打开菜单的按钮:它像浏览器标签页那样打开。
  • 触屏按住时,手指没抬起就不要打开菜单:抬起时才打开,这样按住后移动可以是拖动。
  • 网页的标签页用页面标题命名,只在还没有标题时用域名;从不用网址。它是哪个网站,由地址行里的 SiteDomain 说明。

API

Tab

实验性One tab of a pane's TabBar, built on `TabsTab` inside the bar's `Tabs` › `TabsList` (roving focus, arrow keys, `role="tab"`). It says what the object is, its icon and title, and holds none of the object's actions. TabBar sets its width, and says whether it is in front (the bar's `value`) and how much it shows (the bar's `density`).
Prop类型默认值
draggingThe tab a drag came from: it stays in place at 40%.boolean
icon (required)16px. The App's registered icon, a globe for a site, the object's icon.ReactNode
insecureA `site` over http: Not secure before its title or domain; a title-only tab leaves it to the address row.boolean
locatedA new value each time the tab is opened again and shown in place of a second copy: the located highlight, once (states.md#located).string | number
menuThe tab's menu: `ContextMenu` items for what is done to the tab and its pane. As in a browser it has no button: it opens on right-click, on Shift+F10 or the context-menu key while the tab has focus, and on a touch screen when a 500ms hold ends without moving (a hold that moves is a drag).ReactNode
menuHandsFocusRead once as the menu closes: true when the item chosen moved focus on (a dialog); otherwise focus returns to the tab.() => boolean
messagesPartial<TabMessages>
onCloseCloses the tab, given its `value`: the ×, Delete or Backspace on the focused tab, and a middle click. Not on a pinned tab. One handler can serve every tab of a bar.(value: string) => void
pageTitleA `site`'s page title: the tab's name, as in a browser. Empty while the page has none, and the tab shows the domain. Never the URL.string
pinnedPinned: first in the bar, its icon only, centred, no ×.boolean
prefixBefore the title, in the regular weight: a task's reference (`#launch-week:#25`). In a narrow tab the place gives way first; the number and the start of the title always stay.string
shiftPx the tab slides right while a drop opens a gap before it (`TAB_DROP_GAP`).number
source (required)`app`: the App's registered name and icon; `site`: a web page, named by its `pageTitle`, or by its domain (drawn with SiteDomain) while it has none; `object`: the app's own object (a document, a task, a file).TabSource
squeezedAnother pane's tab while the bar's pane is maximized (the bar's `squeezed`, after its divider): dimmed, no ×, given only the room the bar's own tabs leave (then listed in All tabs), never the front tab; choosing it is the app's, to restore with. Its `menu` still opens. A tab merged into the bar in a narrow window is not squeezed: it is a whole tab, in the bar's `merged`.boolean
title (required)The App's name, the site's host (`URL.host`), or the object's title. A `site` shows it only while it has no `pageTitle`.string
unreadNew things that can be counted (new replies, new comments): a count after the title.number
unreadDotA new thing that can't be counted (a new version): an attention dot after the title.boolean
value (required)The tab's value in its `Tabs` (the tab's id). It is in front when it is its TabBar's `value`.string
waitingSignInThe page asked to sign in while hidden: a key after the title until the tab is shown.boolean

Also takes the attributes of its element.