js-components-container-stepper.md 6.8 KB
Newer Older
E
ester.zhou 已提交
1
# stepper
Z
zengyawen 已提交
2

E
ester.zhou 已提交
3 4 5 6
>  **NOTE**
>
>  This component is supported since API version 5. Updates will be marked with a superscript to indicate their earliest API version.

E
ester.zhou 已提交
7 8
The **\<stepper>** component provides a step navigator. When multiple steps are required to complete a task, you can use the **\<stepper>** component to navigate your users through the whole process.

E
ester.zhou 已提交
9 10

## Required Permissions
Z
zengyawen 已提交
11 12 13 14

None


E
ester.zhou 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
## Child Components

Only the **\<stepper-item>** component is supported.

>  **NOTE**
>
>  Steps in the **\<stepper>** are sorted according to the sequence of its **\<stepper-item>** child components.


## Attributes

In addition to the [universal attributes](../arkui-js/js-components-common-attributes.md), the following attributes are supported.

| Name   | Type    | Default Value | Description                            |
| ----- | ------ | ---- | ------------------------------ |
E
ester.zhou 已提交
30
| index | number | 0    | Index of the **\<stepper-item>** child component to display. By default, the first one is displayed.|
E
ester.zhou 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48


## Styles

The [universal styles](../arkui-js/js-components-common-styles.md) are supported.

>  **NOTE**
>
>  By default, the **\<stepper>** component fills entire space of its container. To optimize user experience, it is recommended that the container should be as large as the application window in size, or should be the root component.


## Events

In addition to the [universal events](../arkui-js/js-components-common-events.md), the following events are supported.

| Name    | Parameter                                      | Description                                      |
| ------ | ---------------------------------------- | ---------------------------------------- |
| finish | -                                       | Triggered when the last step on the navigator is complete.                   |
E
ester.zhou 已提交
49
| skip   | -                                       | Triggered when users click the skip button to skip steps.|
E
ester.zhou 已提交
50
| change | { prevIndex: prevIndex, index: index} | Triggered when users click the left or right (text) button of the step navigator to switch between steps. **prevIndex** indicates the index of the previous step, and **index** indicates that of the current step.|
E
ester.zhou 已提交
51 52
| next   | { index: index, pendingIndex: pendingIndex } | Triggered when users click the next (text) button. **index** indicates the index of the current step, and **pendingIndex** indicates that of the step to go. The return value is in { pendingIndex: pendingIndex } format. You can use **pendingIndex** to specify a **\<stepper-item>** child component as the next step to go. |
| back   | { index: index, pendingIndex: pendingIndex } | Triggered when users click the previous (text) button. **index** indicates the index of the current step, and **pendingIndex** indicates that of the step to go. The return value is in Object: { pendingIndex: pendingIndex } format. You can use **pendingIndex** to specify a **\<stepper-item>** child component as the previous step. |
E
ester.zhou 已提交
53 54 55 56 57 58 59 60


## Methods

In addition to the [universal methods](../arkui-js/js-components-common-methods.md), the following methods are supported.

| Name                 | Parameter                                      | Description                                      |
| ------------------- | ---------------------------------------- | ---------------------------------------- |
E
ester.zhou 已提交
61
| setNextButtonStatus | { status: string, label: label } | Sets the text and status of the next button in the step navigator. **label** indicates the button text, and **status** indicates the button status. Available **status** values are as follows:<br>- **normal**: The next button is displayed normally and can navigate users to the next step when it is clicked.<br>- **disabled**: The next button is grayed out and unavailable.<br>- **waiting**: The next button is not displayed, and a process bar is displayed instead.<br>- **skip**: The skip button is displayed to allow users to skip all remaining steps.|
E
ester.zhou 已提交
62 63 64 65 66


## Example

```html
Z
zengyawen 已提交
67
<!-- xxx.hml -->
E
ester.zhou 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
<div class="container">
    <stepper class="stepper" id="mystepper" onnext="nextclick" onback="backclick" onchange="statuschange"
             onfinish="finish" onskip="skip" style="height : 100%;">
        <stepper-item class="stepper-item" label="{{ label_1 }}">
            <div class="item">
                <text>Page One</text>
                <button type="capsule" class="button" value="change status" onclick="setRightButton"></button>
            </div>
        </stepper-item>
        <stepper-item class="stepper-item" label="{{ label_2 }}">
            <div class="item">
                <text>Page Two</text>
                <button type="capsule" class="button" value="change status" onclick="setRightButton"></button>
            </div>
        </stepper-item>
        <stepper-item class="stepper-item" label="{{ label_3 }}">
            <div class="item">
                <text>Page Three</text>
                <button type="capsule" class="button" value="change status" onclick="setRightButton"></button>
            </div>
        </stepper-item>
    </stepper>
Z
zengyawen 已提交
90 91 92
</div>
```

E
ester.zhou 已提交
93
```css
Z
zengyawen 已提交
94 95
/* xxx.css */
.container {
E
ester.zhou 已提交
96 97 98 99 100
    flex-direction: column;
    align-items: center;
    height: 100%;
    width: 100%;
    background-color: #f7f7f7;
Z
zengyawen 已提交
101
}
E
ester.zhou 已提交
102 103 104
.stepper{
    width: 100%;
    height: 100%;
Z
zengyawen 已提交
105
}
E
ester.zhou 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
.stepper-item {
    width: 100%;
    height: 100%;
    flex-direction: column;
    align-items: center;
}
.item{
    width: 90%;
    height: 86%;
    margin-top: 80px;
    background-color: white;
    border-radius: 60px;
    flex-direction: column;
    align-items: center;
    padding-top: 160px;
}
text {
    font-size: 78px;
    color: #182431;
    opacity: 0.4;
Z
zengyawen 已提交
126 127
}
.button {
E
ester.zhou 已提交
128 129 130
    width: 40%;
    margin-top: 100px;
    justify-content: center;
Z
zengyawen 已提交
131 132 133
}
```

E
ester.zhou 已提交
134
```js
Z
zengyawen 已提交
135
// xxx.js
E
ester.zhou 已提交
136
import prompt from '@ohos.promptAction';
E
ester.zhou 已提交
137

Z
zengyawen 已提交
138
export default {
E
ester.zhou 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
    data: {
        label_1:
        {
            prevLabel: 'BACK',
            nextLabel: 'NEXT',
            status: 'normal'
        },
        label_2:
        {
            prevLabel: 'BACK',
            nextLabel: 'NEXT',
            status: 'normal'
        },
        label_3:
        {
            prevLabel: 'BACK',
            nextLabel: 'NEXT',
            status: 'normal'
        }
    },
    setRightButton(e) {
        this.$element('mystepper').setNextButtonStatus({
            status: 'waiting', label: 'SKIP'
        });
    },
    nextclick(e) {
        var index = {
            pendingIndex: e.pendingIndex
        }
        return index;
    },
    backclick(e) {
        var index = {
            pendingIndex: e.pendingIndex
        }
        return index;
    },
    statuschange(e) {
        prompt.showToast({
            message: 'Previous step index' + e.prevIndex + 'Current step index' + e.index
        })
    },
    finish() {
        prompt.showToast({
            message:'Finished.'
        })
    },
    skip() {
        prompt.showToast({
            message: 'Skip triggered'
        })
Z
zengyawen 已提交
190 191 192 193
    }
}
```

E
ester.zhou 已提交
194
![](figures/stepper.gif)