步进器组件通过引导用户完成多步骤流程来显示类似向导的工作流程。
import { Stepper } from 'primereact/stepper';
import { StepperPanel } from 'primereact/stepperpanel';
步进器由一个或多个 StepperPanel 元素组成,以封装进度中的每个步骤。步骤之间导航的元素不是内置的,以便于自定义,而是应该将prevCallback和 nextCallback事件绑定到你的自定义 UI 元素。
<Stepper ref={stepperRef} style={{ flexBasis: '50rem' }}>
<StepperPanel header="Header I">
<div className="flex flex-column h-12rem">
<div className="border-2 border-dashed surface-border border-round surface-ground flex-auto flex justify-content-center align-items-center font-medium">Content I</div>
</div>
<div className="flex pt-4 justify-content-end">
<Button label="Next" icon="pi pi-arrow-right" iconPos="right" onClick={() => stepperRef.current.nextCallback()} />
</div>
</StepperPanel>
<StepperPanel header="Header II">
<div className="flex flex-column h-12rem">
<div className="border-2 border-dashed surface-border border-round surface-ground flex-auto flex justify-content-center align-items-center font-medium">Content II</div>
</div>
<div className="flex pt-4 justify-content-between">
<Button label="Back" severity="secondary" icon="pi pi-arrow-left" onClick={() => stepperRef.current.prevCallback()} />
<Button label="Next" icon="pi pi-arrow-right" iconPos="right" onClick={() => stepperRef.current.nextCallback()} />
</div>
</StepperPanel>
<StepperPanel header="Header III">
<div className="flex flex-column h-12rem">
<div className="border-2 border-dashed surface-border border-round surface-ground flex-auto flex justify-content-center align-items-center font-medium">Content III</div>
</div>
<div className="flex pt-4 justify-content-start">
<Button label="Back" severity="secondary" icon="pi pi-arrow-left" onClick={() => stepperRef.current.prevCallback()} />
</div>
</StepperPanel>
</Stepper>
步进器的布局通过orientation属性配置,该属性接受horizontal和vertical作为可用选项。
<Stepper ref={stepperRef} style={{ flexBasis: '50rem' }} orientation="vertical">
<StepperPanel header="Header I">
<div className="flex flex-column h-12rem">
<div className="border-2 border-dashed surface-border border-round surface-ground flex-auto flex justify-content-center align-items-center font-medium">Content I</div>
</div>
<div className="flex py-4">
<Button label="Next" icon="pi pi-arrow-right" iconPos="right" onClick={() => stepperRef.current.nextCallback()} />
</div>
</StepperPanel>
<StepperPanel header="Header II">
<div className="flex flex-column h-12rem">
<div className="border-2 border-dashed surface-border border-round surface-ground flex-auto flex justify-content-center align-items-center font-medium">Content II</div>
</div>
<div className="flex py-4 gap-2">
<Button label="Back" severity="secondary" icon="pi pi-arrow-left" onClick={() => stepperRef.current.prevCallback()} />
<Button label="Next" icon="pi pi-arrow-right" iconPos="right" onClick={() => stepperRef.current.nextCallback()} />
</div>
</StepperPanel>
<StepperPanel header="Header III">
<div className="flex flex-column h-12rem">
<div className="border-2 border-dashed surface-border border-round surface-ground flex-auto flex justify-content-center align-items-center font-medium">Content III</div>
</div>
<div className="flex py-4">
<Button label="Back" severity="secondary" icon="pi pi-arrow-left" onClick={() => stepperRef.current.prevCallback()} />
</div>
</StepperPanel>
</Stepper>
当存在linear属性时,必须完成当前步骤才能移动到下一步。
<Stepper ref={stepperRef} style={{ flexBasis: '50rem' }}>
<StepperPanel header="Header I">
<div className="flex flex-column h-12rem">
<div className="border-2 border-dashed surface-border border-round surface-ground flex-auto flex justify-content-center align-items-center font-medium">Content I</div>
</div>
<div className="flex pt-4 justify-content-end">
<Button label="Next" icon="pi pi-arrow-right" iconPos="right" onClick={() => stepperRef.current.nextCallback()} />
</div>
</StepperPanel>
<StepperPanel header="Header II">
<div className="flex flex-column h-12rem">
<div className="border-2 border-dashed surface-border border-round surface-ground flex-auto flex justify-content-center align-items-center font-medium">Content II</div>
</div>
<div className="flex pt-4 justify-content-between">
<Button label="Back" severity="secondary" icon="pi pi-arrow-left" onClick={() => stepperRef.current.prevCallback()} />
<Button label="Next" icon="pi pi-arrow-right" iconPos="right" onClick={() => stepperRef.current.nextCallback()} />
</div>
</StepperPanel>
<StepperPanel header="Header III">
<div className="flex flex-column h-12rem">
<div className="border-2 border-dashed surface-border border-round surface-ground flex-auto flex justify-content-center align-items-center font-medium">Content III</div>
</div>
<div className="flex pt-4 justify-content-start">
<Button label="Back" severity="secondary" icon="pi pi-arrow-left" onClick={() => stepperRef.current.prevCallback()} />
</div>
</StepperPanel>
</Stepper>
可以使用headerPosition属性自定义步进器的标题位置。默认值为right。
<h5>Position top</h5>
<Stepper ref={(ref) => (stepperRef.current[2] = ref)} headerPosition="top">
<StepperPanel header="Header I"></StepperPanel>
<StepperPanel header="Header II"></StepperPanel>
<StepperPanel header="Header III"></StepperPanel>
</Stepper>
<h5>Position right</h5>
<Stepper ref={(ref) => (stepperRef.current[0] = ref)} headerPosition="right">
<StepperPanel header="Header I"></StepperPanel>
<StepperPanel header="Header II"></StepperPanel>
<StepperPanel header="Header III"></StepperPanel>
</Stepper>
<h5>Position left</h5>
<Stepper ref={(ref) => (stepperRef.current[1] = ref)} headerPosition="left">
<StepperPanel header="Header I"></StepperPanel>
<StepperPanel header="Header II"></StepperPanel>
<StepperPanel header="Header III"></StepperPanel>
</Stepper>
<h5>Position bottom</h5>
<Stepper ref={(ref) => (stepperRef.current[2] = ref)} headerPosition="bottom">
<StepperPanel header="Header I"></StepperPanel>
<StepperPanel header="Header II"></StepperPanel>
<StepperPanel header="Header III"></StepperPanel>
</Stepper>
步进器容器使用tablist角色定义,由于任何属性都传递到容器元素,因此可以可选地使用aria-labelledby来指定元素以描述步进器。每个步进器标题都有一个tab角色和aria-controls来引用相应的步进器内容元素。每个步进器的内容元素都有tabpanel角色,一个与标题的aria-controls匹配的 id 和一个引用标题作为可访问名称的aria-labelledby。
按键 | 功能 |
---|---|
tab | 在标题中移动焦点。 |
enter | 激活聚焦的步进器标题。 |
space | 激活聚焦的步进器标题。 |