145a208687
HD-04 scope, against heroui ce90ea3 cn sources: - stale/fictional content: input.md no longer claims TextField is unmigrated; color-field.md no longer claims ColorPicker is private; header.md drops the fictional Header.Root subcomponent and the stale 'menus not migrated' wording (MenuSection label registration is now documented from HeaderRoot source); radio-group.md drops three copied CheckboxGroup wordings (variant override is Radio's, scalar emits, native single-value submit); input-otp.md drops the fictional data-complete state and lists the real missing upstream props - toggle-button disabled row now matches the real CSS hooks (:disabled / [aria-disabled], with data-disabled as a marker only) - part API / CSS classes / interactive states restored per pinned sources: button (full class lists + real variable-based global CSS), accordion (per-part tables + variant/state lists), card (per-part tables + variant list), switch (SwitchGroup snippet + Switch/ SwitchGroup class lists + states), color-field Group (class list + states), input-otp (variant notes, global CSS, class/state lists); input-group gains the two upstream usage chapters - RelatedComponents restored from the pinned componentRelationships (first-3, filtered against componentsMap): 64 pages rewritten, list-box/slider sections added, 7 empty-mapping pages' fabricated entries removed; RelatedShowcases left unmigrated with its real data inventory recorded (2 cases, showcase-site cards) - defaults unified on implementation evidence: granularity (inferred day/minute) and visibleYears (full min-max span, no "or 20" fallback); HD-03 hand-offs resolved (trigger focus-visible noted for HD-06, width guards kept) - new demos: header-collection-grouping (MenuSection/ListBoxSection label wiring), empty-state-collection (collection empty slot); empty-state page deduplicated with a boundary compatibility note - ComponentPreview minHeight/isBgSolid restored per the 30 upstream marks; tabs-overflow max-w-full kept after measuring internal scroll - tests: +3 header registration/demo cases, +1 empty-state collection case; full suite 110 files / 1630 tests, typecheck and build:docs pass
96 lines
3.4 KiB
Markdown
96 lines
3.4 KiB
Markdown
---
|
|
title: Toolbar 工具栏
|
|
description: 用于承载可交互控件的容器,并支持方向键导航。
|
|
component: toolbar
|
|
group: 组件
|
|
---
|
|
|
|
## 用法
|
|
|
|
```vue
|
|
<script setup lang="ts">
|
|
import { Toolbar } from "@heroui-vue/components";
|
|
</script>
|
|
```
|
|
|
|
<ComponentPreview name="toolbar-basic" />
|
|
|
|
## 示例
|
|
|
|
### 垂直方向
|
|
|
|
<ComponentPreview name="toolbar-vertical" />
|
|
|
|
### 组合模式
|
|
|
|
<ComponentPreview name="toolbar-attached" />
|
|
|
|
### 与 ButtonGroup 组合
|
|
|
|
<ComponentPreview name="toolbar-with-button-group" />
|
|
|
|
## 自定义样式
|
|
|
|
### Tailwind CSS
|
|
|
|
<ComponentPreview name="toolbar-custom-styles" />
|
|
|
|
### 全局 CSS
|
|
|
|
若要自定义组件类,可使用 `@layer components` 指令。
|
|
|
|
```css
|
|
@layer components {
|
|
.hv-toolbar {
|
|
@apply gap-4 rounded-lg bg-surface p-3;
|
|
}
|
|
}
|
|
```
|
|
|
|
## 样式参考
|
|
|
|
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。
|
|
|
|
### CSS 类
|
|
|
|
Toolbar 使用以下 CSS 类:
|
|
|
|
- `.hv-toolbar` - 基础容器
|
|
- `.hv-toolbar--horizontal` - 水平方向(默认)
|
|
- `.hv-toolbar--vertical` - 垂直方向
|
|
- `.hv-toolbar--attached` - Attached 变体:surface 背景与完全圆角
|
|
|
|
## API 参考
|
|
|
|
### Toolbar
|
|
|
|
| Prop | 类型 | 默认值 | 描述 |
|
|
| ----------------- | ---------------------------- | ------------------- | ----------------------------------------- |
|
|
| `isAttached` | `boolean` | `false` | Toolbar 是否使用带完全圆角的 surface 背景 |
|
|
| `orientation` | `'horizontal' \| 'vertical'` | `'horizontal'` | Toolbar 的方向 |
|
|
| `dir` | `'ltr' \| 'rtl'` | 继承 ConfigProvider | 阅读方向,影响方向键 |
|
|
| `as` | `string` | `'div'` | 渲染的根元素 |
|
|
| `aria-label` | `string` | - | Toolbar 的无障碍标签 |
|
|
| `aria-labelledby` | `string` | - | 用于标注该 Toolbar 的元素 id |
|
|
| `class` | `string` | - | 额外的 CSS 类名 |
|
|
|
|
### 作用域插槽
|
|
|
|
| 名称 | 参数 | 描述 |
|
|
| --------- | ----------------- | ------------------------------------ |
|
|
| `default` | `{ orientation }` | 内容;`orientation` 为当前工具栏方向 |
|
|
|
|
## 说明
|
|
|
|
- Toolbar 提供 `role="toolbar"` 与 `aria-orientation`
|
|
- **焦点所有权**:工具栏内所有可聚焦按钮(Button、ToggleButton,含 ButtonGroup / ToggleButtonGroup 成员)由 Toolbar 统一做单 Tab 入口与方向键遍历,可跨子组移动;嵌套 Toolbar 各自隔离
|
|
- 子组在 Toolbar 内不再自行处理方向键,避免一次按键双重导航
|
|
- `ToggleButtonGroup` 未显式指定时继承 Toolbar 的 `orientation`;显式属性优先,取消覆盖后恢复继承
|
|
- `Separator` 在 Toolbar 内默认取与工具栏垂直的方向,可显式覆盖
|
|
- `ButtonGroup` 继承 Toolbar 方向(与上游 ToggleButtonGroup 缺省 orientation 一致)
|
|
- React 渲染 prop `children(values)` 转为作用域插槽 `{ orientation }`
|
|
|
|
## 相关组件
|
|
|
|
[ButtonGroup 按钮组](./button-group) · [ToggleButtonGroup 切换按钮组](./toggle-button-group) · [Separator 分隔符](./separator)
|