1# Stepper 2 3The **Stepper** component provides a step navigator, suitable for guiding users through a step-by-step task completion process. 4 5 6> **NOTE** 7> 8> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. 9 10 11## Child Components 12 13Only the child component [StepperItem](ts-basic-components-stepperitem.md) is supported. 14 15 16## APIs 17 18Stepper(value?: { index?: number }) 19 20**Atomic service API**: This API can be used in atomic services since API version 11. 21 22**System capability**: SystemCapability.ArkUI.ArkUI.Full 23 24**Parameters** 25 26| Name| Type| Mandatory | Description| 27| ------| -------- | --------------- | -------- | 28| value | { index?: number } | No| Index of the **StepperItem** that is currently displayed.<br>Default value: **0**<br>Since API version 10, this parameter supports two-way binding through [$$](../../../quick-start/arkts-two-way-sync.md).| 29 30 31## Attributes 32 33None 34 35## Events 36 37### onFinish 38 39onFinish(callback: () => void) 40 41Invoked when the **nextLabel** of the last **StepperItem** in the **Stepper** is clicked and the **ItemState** attribute is set to **Normal**. 42 43**Atomic service API**: This API can be used in atomic services since API version 11. 44 45**System capability**: SystemCapability.ArkUI.ArkUI.Full 46 47### onSkip 48 49onSkip(callback: () => void) 50 51Invoked when the current **StepperItem** is **ItemState.Skip** and the **nextLabel** is clicked. 52 53**Atomic service API**: This API can be used in atomic services since API version 11. 54 55**System capability**: SystemCapability.ArkUI.ArkUI.Full 56 57### onChange 58 59onChange(callback: (prevIndex: number, index: number) => void) 60 61Invoked when the **prevLabel** of the current **StepperItem** is clicked to switch to the previous step page; or when the **nextLabel** of the current (not the last) **StepperItem** is clicked to switch to the next step page and the **ItemState** attribute is set to **Normal**. 62 63**Atomic service API**: This API can be used in atomic services since API version 11. 64 65**System capability**: SystemCapability.ArkUI.ArkUI.Full 66 67**Parameters** 68 69| Name | Type | Mandatory| Description | 70| --------- | ------ | ---- | ------------------------------------------ | 71| prevIndex | number | Yes | Index of the step page before the switching.<br>Value range: [0, +∞)| 72| index | number | Yes | Index of the step page after the switching, that is, index of the previous or next page.<br>Value range: [0, +∞)| 73 74### onNext 75 76onNext(callback: (index: number, pendingIndex: number) => void) 77 78Invoked when the **nextLabel** of the current (not the last) **StepperItem** is clicked and the **ItemState** attribute is set to **Normal**. 79 80**Atomic service API**: This API can be used in atomic services since API version 11. 81 82**System capability**: SystemCapability.ArkUI.ArkUI.Full 83 84**Parameters** 85 86| Name | Type | Mandatory| Description | 87| ------------ | ------ | ---- | ------------------ | 88| index | number | Yes | Index of the current step page.| 89| pendingIndex | number | Yes | Index of the next step page.| 90 91### onPrevious 92 93onPrevious(callback: (index: number, pendingIndex: number) => void) 94 95Invoked when the **prevLabel** of the current **StepperItem** is clicked to switch to the previous step page. 96 97**Atomic service API**: This API can be used in atomic services since API version 11. 98 99**System capability**: SystemCapability.ArkUI.ArkUI.Full 100 101**Parameters** 102 103| Name | Type | Mandatory| Description | 104| ------------ | ------ | ---- | ------------------ | 105| index | number | Yes | Index of the current step page.| 106| pendingIndex | number | Yes | Index of the previous step page.| 107 108 109## Example 110 111This example demonstrates how to use the **Stepper** component. 112 113```ts 114// xxx.ets 115@Styles function itemStyle () { 116 .width(336) 117 .height(621) 118 .margin({ top: 48, left: 12 }) 119 .borderRadius(24) 120 .backgroundColor('#FFFFFF') 121} 122 123@Extend(Text) function itemTextStyle () { 124 .fontColor('#182431') 125 .fontSize(36) 126 .fontWeight(500) 127 .opacity(0.4) 128 .margin({ top: 82, bottom: 40 }) 129} 130 131@Entry 132@Component 133struct StepperExample { 134 @State currentIndex: number = 0 135 @State firstState: ItemState = ItemState.Normal 136 @State secondState: ItemState = ItemState.Normal 137 @State thirdState: ItemState = ItemState.Normal 138 139 build() { 140 Stepper({ 141 index: this.currentIndex 142 }) { 143 // First step page 144 StepperItem() { 145 Column() { 146 Text('Page One') 147 .itemTextStyle() 148 Button('change status:' + this.firstState) 149 .backgroundColor('#007dFF') 150 .onClick(() => { 151 this.firstState = this.firstState === ItemState.Skip ? ItemState.Normal : ItemState.Skip 152 }) 153 }.itemStyle() 154 } 155 .nextLabel('Next') 156 .status(this.firstState) 157 // Second step page 158 StepperItem() { 159 Column() { 160 Text('Page Two') 161 .itemTextStyle() 162 Button('change status:' + this.secondState) 163 .backgroundColor('#007dFF') 164 .onClick(() => { 165 this.secondState = this.secondState === ItemState.Disabled ? ItemState.Normal : ItemState.Disabled 166 }) 167 }.itemStyle() 168 } 169 .nextLabel('Next') 170 .prevLabel('Previous') 171 .status(this.secondState) 172 // Third step page 173 StepperItem() { 174 Column() { 175 Text('Page Three') 176 .itemTextStyle() 177 Button('change status:' + this.thirdState) 178 .backgroundColor('#007dFF') 179 .onClick(() => { 180 this.thirdState = this.thirdState === ItemState.Waiting ? ItemState.Normal : ItemState.Waiting 181 }) 182 }.itemStyle() 183 } 184 .status(this.thirdState) 185 // Fourth step page 186 StepperItem() { 187 Column() { 188 Text('Page Four') 189 .itemTextStyle() 190 }.itemStyle() 191 } 192 } 193 .backgroundColor('#F1F3F5') 194 .onFinish(() => { 195 // Define the processing logic for when Finish on the last page is clicked, for example, redirection. 196 console.info('onFinish') 197 }) 198 .onSkip(() => { 199 // Define the processing logic for when Skip on the page is clicked, for example, dynamically changing the index of the <Stepper> to redirect to a specific step. 200 console.info('onSkip') 201 }) 202 .onChange((prevIndex?: number, index?: number) => { 203 if(index){ 204 this.currentIndex = index 205 } 206 }) 207 } 208} 209``` 210 211 212 213