feat: migrate Pagination Header and InputOTP with field and event regressions
This commit is contained in:
@@ -0,0 +1,296 @@
|
||||
---
|
||||
title: Pagination 分页
|
||||
description: 分页导航:可组合的页码链接、上一页/下一页按钮与省略号指示器。
|
||||
component: pagination
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Pagination>
|
||||
<PaginationContent>
|
||||
<PaginationItem>
|
||||
<PaginationLink is-active>1</PaginationLink>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</template>
|
||||
```
|
||||
|
||||
<ComponentPreview name="pagination-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
导入 Pagination 各具名组件后组合使用。根组件同时以 `Pagination` 与 `PaginationRoot` 导出,二者是同一实现。
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationEllipsis,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
PaginationNext,
|
||||
PaginationNextIcon,
|
||||
PaginationPrevious,
|
||||
PaginationPreviousIcon,
|
||||
PaginationSummary,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Pagination>
|
||||
<PaginationSummary>显示第 1–10 条,共 100 条结果</PaginationSummary>
|
||||
<PaginationContent>
|
||||
<PaginationItem>
|
||||
<PaginationPrevious>
|
||||
<PaginationPreviousIcon />
|
||||
<span>上一页</span>
|
||||
</PaginationPrevious>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationLink is-active>1</PaginationLink>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationEllipsis />
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationLink>10</PaginationLink>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationNext>
|
||||
<span>下一页</span>
|
||||
<PaginationNextIcon />
|
||||
</PaginationNext>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</template>
|
||||
```
|
||||
|
||||
根 `Pagination` 渲染为带 `aria-label="pagination"` 与 `role="navigation"` 的 `nav`,`Content` 为 `ul`,`Item` 为 `li`。根组件是组合式导航容器,不管理 `total` / `page` 状态;受控示例的页码由示例自身维护。
|
||||
|
||||
`Link` / `Previous` / `Next` 在固定基线使用 React Aria Button(原生 `button`,默认 `type="button"`),不是 `a`。名字叫 Link 但语义是按钮。
|
||||
|
||||
## 示例
|
||||
|
||||
### 尺寸
|
||||
|
||||
<ComponentPreview name="pagination-sizes" />
|
||||
|
||||
### 禁用
|
||||
|
||||
<ComponentPreview name="pagination-disabled" />
|
||||
|
||||
`isDisabled` 禁用按钮的原生激活与点击;页码链接仍可单独控制。
|
||||
|
||||
### 简化(上一页 / 下一页)
|
||||
|
||||
<ComponentPreview name="pagination-simple-prev-next" />
|
||||
|
||||
### 受控组件
|
||||
|
||||
<ComponentPreview name="pagination-controlled" />
|
||||
|
||||
页码列表、省略号与摘要区间由示例根据 `page` 计算;组件根不额外实现分页状态机。
|
||||
|
||||
### 带省略号
|
||||
|
||||
<ComponentPreview name="pagination-with-ellipsis" />
|
||||
|
||||
### 带摘要
|
||||
|
||||
<ComponentPreview name="pagination-with-summary" />
|
||||
|
||||
### 自定义图标
|
||||
|
||||
可通过向 `PreviousIcon` 与 `NextIcon` 传入默认插槽替换默认 chevron 图标。空插槽回退到基线 SVG;图标包裹层始终 `aria-hidden="true"`。
|
||||
|
||||
<ComponentPreview name="pagination-custom-icons" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="pagination-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
若要自定义组件类,可使用 `@layer components` 指令。[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-pagination {
|
||||
@apply gap-8;
|
||||
}
|
||||
|
||||
.hv-pagination__link {
|
||||
@apply rounded-md;
|
||||
}
|
||||
|
||||
.hv-pagination__summary {
|
||||
@apply text-xs font-semibold;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||||
|
||||
### CSS 类
|
||||
|
||||
Pagination 使用以下 CSS 类:
|
||||
|
||||
#### 基础与布局类 [!toc]
|
||||
|
||||
- `.hv-pagination` - 根导航容器(flex 布局)
|
||||
- `.hv-pagination__summary` - 左侧信息文本容器
|
||||
- `.hv-pagination__content` - 分页项容器
|
||||
- `.hv-pagination__item` - 单个分页项包裹层
|
||||
- `.hv-pagination__link` - 页码按钮(ghost 按钮样式)
|
||||
- `.hv-pagination__link--nav` - 导航按钮修饰符(Previous/Next)
|
||||
- `.hv-pagination__ellipsis` - 省略号指示器
|
||||
|
||||
#### 尺寸类 [!toc]
|
||||
|
||||
- `.hv-pagination--sm` - 小尺寸变体
|
||||
- `.hv-pagination--md` - 中尺寸变体(默认)
|
||||
- `.hv-pagination--lg` - 大尺寸变体
|
||||
|
||||
### 交互状态
|
||||
|
||||
组件同时支持 CSS 伪类与 data 属性,便于灵活定制:
|
||||
|
||||
- **Active page**:`[data-active="true"]` 或 `[aria-current="page"]`
|
||||
- **Hover**:`:hover` 或 `[data-hovered="true"]`
|
||||
- **Focus**:`:focus-visible` 或 `[data-focus-visible="true"]`
|
||||
- **Disabled**:`:disabled` 或 `[aria-disabled="true"]`
|
||||
- **Pressed**:`:active` 或 `[data-pressed="true"]`
|
||||
|
||||
## API 参考
|
||||
|
||||
### Pagination / PaginationRoot
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------- | ------------------------------- |
|
||||
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | 分页控件的尺寸 |
|
||||
| `as` | `string` | `'nav'` | 自定义根元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
| 默认插槽 | - | - | 分页部件(Summary、Content 等) |
|
||||
|
||||
根元素同时接收其余 `$attrs`(`aria-*`、`data-*`、事件等)。未显式传入时默认 `aria-label="pagination"` 与 `role="navigation"`;显式属性优先。
|
||||
|
||||
### PaginationSummary
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------- | -------------------------------------------- |
|
||||
| `as` | `string` | `'div'` | 自定义元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | 摘要内容(例如 “显示第 1–10 条,共 120 条”) |
|
||||
|
||||
默认 `dir="auto"`,按摘要自身文本检测方向,避免 RTL 祖先重排数字/中英混排;显式传入 `dir` 时覆盖。
|
||||
|
||||
### PaginationContent
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | -------------- |
|
||||
| `as` | `string` | `'ul'` | 自定义元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | 分页项 |
|
||||
|
||||
### PaginationItem
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | -------------------------------- |
|
||||
| `as` | `string` | `'li'` | 自定义元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | Link、Previous、Next 或 Ellipsis |
|
||||
|
||||
### PaginationLink
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------ | --------------------------- | ---------- | ---------------------------------------------------------------- |
|
||||
| `isActive` | `boolean` | `false` | 是否为当前页;输出 `aria-current="page"` 与 `data-active="true"` |
|
||||
| `isDisabled` | `boolean` | `false` | 是否禁用按钮 |
|
||||
| `type` | `string` | `'button'` | 原生按钮 type |
|
||||
| `asChild` | `boolean` | `false` | 将属性合并到唯一子元素 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | 页码内容 |
|
||||
|
||||
激活状态取消时移除 `aria-current` 与 `data-active`。显式传入的 `aria-current` 等 ARIA 在未激活时保留调用方值;激活时组件写入 `aria-current="page"`。
|
||||
|
||||
### PaginationPrevious / PaginationNext
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------ | --------------------------- | ---------- | ------------------------------------------- |
|
||||
| `isDisabled` | `boolean` | `false` | 是否禁用按钮 |
|
||||
| `type` | `string` | `'button'` | 原生按钮 type |
|
||||
| `asChild` | `boolean` | `false` | 将属性合并到唯一子元素 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | 按钮内容(可与 PreviousIcon/NextIcon 组合) |
|
||||
|
||||
两者附加 `hv-pagination__link--nav` 修饰类,不带入普通 Button 的 variant 类。
|
||||
|
||||
### PaginationPreviousIcon / PaginationNextIcon
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ---------------- | ----------------------------- |
|
||||
| `as` | `string` | `'span'` | 自定义包裹元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | 默认 chevron SVG | 替换默认 chevron 的自定义图标 |
|
||||
|
||||
包裹层始终 `aria-hidden="true"`。默认图标从 HeroUI `icons.tsx`(Apache-2.0)移植。
|
||||
|
||||
### PaginationEllipsis
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------- | --------------------------- | -------- | -------------- |
|
||||
| `as` | `string` | `'span'` | 自定义元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
|
||||
始终渲染 `…`,带 `aria-hidden="true"`,与上游一致不接受自定义子内容。
|
||||
|
||||
### 上游差异
|
||||
|
||||
| 上游 React 能力 | Vue 实现 |
|
||||
| ---------------------------- | -------------------------------------------------- |
|
||||
| `Pagination.Link` 对象子部件 | 独立具名导出 `PaginationLink` 等 |
|
||||
| `onPress` | 原生 `@click`;原生 button 的 Enter/Space 单次激活 |
|
||||
| `className` / `children` | `class` / 默认插槽 |
|
||||
| `render` / `DOMRenderProps` | `as` 更换元素,属性直接透传 |
|
||||
| 根 `v-model` / 自动页码计算 | 无;固定基线是组合式 nav 容器,页码由示例维护 |
|
||||
|
||||
## 说明
|
||||
|
||||
- 上游 Pagination 按钮使用 React Aria 的 `onPress`。Vue 版使用原生 `button` 与 `@click`:Enter/Space 触发一次原生 click,禁用时不激活,调用方可用 `preventDefault` / `stopPropagation` / 处理器数组 / `stopImmediatePropagation` 控制事件,组件不再手动重复模拟 click。
|
||||
- 分页按钮不复用共享 Button 的 variant 类,只使用 `hv-pagination__link` 族样式,避免带入无关默认外观。
|
||||
|
||||
## 无障碍
|
||||
|
||||
- 语义化 `<nav>` 元素,包含 `aria-label="pagination"` 与 `role="navigation"`(均可被显式属性覆盖)
|
||||
- 当前页链接使用 `aria-current="page"` 与 `data-active="true"`
|
||||
- Tab 键在全部可交互元素间导航(原生按钮)
|
||||
- 键盘激活时通过 `:focus-visible` 显示焦点环
|
||||
- 省略号与图标使用 `aria-hidden="true"`,避免干扰屏幕阅读器
|
||||
- 通过 `isDisabled` / 原生 `disabled` 向辅助技术正确传达禁用状态
|
||||
|
||||
真实键盘激活与焦点环在浏览器验证;jsdom 测试只覆盖 DOM/ARIA 与事件合并,不冒充浏览器已验收。
|
||||
|
||||
## 相关组件
|
||||
|
||||
- [Button 按钮](./button)
|
||||
- [Breadcrumbs 面包屑](./breadcrumbs)
|
||||
- [Separator 分隔符](./separator)
|
||||
Reference in New Issue
Block a user