Skip to content

Steps 步骤条 ​

用带手绘描边的节点展示流程进度。Steps 只负责呈现当前步骤、状态与连接线,流程推进由消费者更新 active。

使用提示步骤条表达有先后顺序的流程。没有顺序的并列内容请使用 Tabs 或卡片布局。

注册 ​

主入口 import "yxzq-element" 会随全部组件注册 super-steps。只注册步骤条或需要显式控制注册时机时,使用:

ts
import "yxzq-element/steps";

// SSR 或自定义注册时机
import { defineSuperSteps } from "yxzq-element/steps";
defineSuperSteps();

重复注册是安全的;没有 customElements 时不会抛错。

基础用法 ​

通过 items 传入步骤,active 是从 0 开始的当前索引。索引之前的步骤显示为完成态,之后为等待态,当前步使用 status 指定的状态。

html
<super-steps active="1" aria-label="发布流程"></super-steps>
ts
const steps = document.querySelector("super-steps");
steps.items = [
  { title: "填写信息", description: "确认项目基础资料" },
  { title: "选择方案", description: "比较并选择适合的方案" },
  { title: "完成", description: "生成并发布站点" },
];
steps.active = 1;

items 是 JavaScript 属性,无法通过 HTML attribute 表达。active 超出范围时会按最近的边界步骤呈现,不会修改消费者保存的值。

状态 ​

status 只作用于当前步骤。process 用主色强调进行中,error 标记失败,finish 与 wait 通常由索引推导;把当前步设为 finish 并定位到最后一步,可以表达整条流程已完成。

进行中
失败
已完成
html
<super-steps status="process"></super-steps>
<super-steps status="error"></super-steps>
<super-steps status="finish"></super-steps>

方向 ​

direction="vertical" 把步骤改为上下排列,连接线随之变成纵向虚线,适合较长的标题和描述。

html
<super-steps direction="vertical"></super-steps>

可点击步骤 ​

开启 clickable 后,每个步骤渲染为原生 button,支持 Tab 聚焦、Enter 与 Space 触发,并派发 super-steps-change。组件不会自行推进流程以外的内容;请在事件中加载对应步骤的数据。

当前步骤:2

html
<super-steps clickable aria-label="可点击的流程"></super-steps>
ts
steps.addEventListener("super-steps-change", (event) => {
  console.log(event.detail.active);
});

点击当前步骤不会重复派发事件。未开启 clickable 时,步骤只读,不进入 Tab 序列。

尺寸 ​

size 调整节点直径、字号与间距,三档尺寸保持相同的语义结构。

大
中
小

无障碍与键盘 ​

外层使用 ol 与 role="list",每步使用 li 与 role="listitem";当前步带 aria-current="step"。节点中的序号与图标、连接线全部 aria-hidden="true",读屏只会朗读标题、描述与当前步语义。

按键行为
Tab / Shift + Tab在可点击步骤之间移动;只读模式下步骤不进入 Tab 序列
Enter / Space激活聚焦的步骤并派发 super-steps-change

请为步骤条提供描述流程用途的 aria-label。标题应简短,补充信息放进 description,不要把关键状态只写在图标里。

受控状态 ​

active 同时支持受控与非受控用法。HTML attribute 初始化只作为非受控默认值;通过 JavaScript property 写入后进入受控模式。

用户点击或键盘激活可点击步骤时,组件会先更新内部步骤并派发 super-steps-change,随后在下一个动画帧确认父级是否写回。父级同步写回新索引即接受切换;不写入时恢复最近一次外部提交值。程序化写入不会派发用户事件。

API ​

Attributes / Properties ​

名称类型默认值说明
activenumber0从 0 开始的当前步骤索引
directionhorizontal | verticalhorizontal排列方向与连接线方向
statusprocess | wait | finish | errorprocess当前步骤的状态
clickablebooleanfalse步骤是否可点击并派发事件
sizelarge | medium | smallmedium节点尺寸、字号与间距
aria-labelstring步骤步骤列表的可访问名称
items{ title, description?, icon? }[][]步骤数据,仅 JavaScript 属性

Events ​

所有自定义事件均支持冒泡,并能穿过 Shadow DOM。

名称detail说明
super-steps-change{ active: number }用户点击或键盘激活其他步骤后触发

程序化修改 active 不会触发 super-steps-change。

Slots ​

Steps 不使用 Slot;标题、描述与图标都来自 items,因此组件不依赖任何图标库。

CSS Parts ​

名称说明
steps外层 ol
step单个步骤 li
indicator序号或图标节点
icon自定义图标容器
title步骤标题
description步骤描述
connector步骤之间的连接线

CSS Custom Properties ​

css
super-steps {
  --super-steps-gap: var(--super-spacing-md);
  --super-steps-indicator-size: 30px;
  --super-steps-title-color: var(--super-text-color-primary);
  --super-steps-description-color: var(--super-text-color-secondary);
  --super-steps-wait-color: var(--super-text-color-secondary);
  --super-steps-process-color: #245cbe;
  --super-steps-finish-color: var(--super-color-success);
  --super-steps-error-color: var(--super-color-danger);
  --super-steps-connector-color: var(--super-border-color-light);
  --super-steps-focus-color: var(--super-focus-color);
  --super-steps-indicator-radius: 52% 48% 55% 45% / 47% 53% 45% 55%;
  --super-steps-rotation: var(--super-sketch-rotation);
}

已知边界 ​

super-steps 不是 form-associated Custom Element,不参与 FormData、原生重置或约束验证。组件不校验步骤顺序,也不阻止消费者直接跳到最后一步;需要线性推进时请自行在 super-steps-change 中判断。Steps 只呈现当前 active,不保存历史状态,也不负责步骤内容的切换。横向步骤不会自动换行,步骤较多时请改用 direction="vertical" 或缩短标题。