diff --git a/packages/components/steps/__tests__/steps.test.tsx b/packages/components/steps/__tests__/steps.test.tsx
index ff120db518..1dde35a9a4 100644
--- a/packages/components/steps/__tests__/steps.test.tsx
+++ b/packages/components/steps/__tests__/steps.test.tsx
@@ -1,4 +1,4 @@
-import { markRaw, nextTick } from 'vue'
+import { markRaw, nextTick, ref } from 'vue'
import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
import { Edit } from '@element-plus/icons-vue'
@@ -190,4 +190,26 @@ describe('Steps.vue', () => {
expect(wrapper.find('.el-step__title').text()).toBe('A')
expect(wrapper.find('.el-step__description').text()).toBe('B')
})
+
+ test('order of step', async () => {
+ const data = ref(['first', 'second', 'thrid'])
+ const wrapper = _mount(() => (
+
+ {data.value.map((t) => (
+ t,
+ }}
+ />
+ ))}
+
+ ))
+ await nextTick()
+ data.value = ['a', 'b', 'c']
+ await nextTick()
+ wrapper.findAll('.el-step__icon-inner').forEach((domWrapper, index) => {
+ expect(domWrapper.element.textContent).toEqual((index + 1).toString())
+ })
+ })
})
diff --git a/packages/components/steps/src/item.vue b/packages/components/steps/src/item.vue
index efeb994f59..a240e95e76 100644
--- a/packages/components/steps/src/item.vue
+++ b/packages/components/steps/src/item.vue
@@ -74,7 +74,7 @@ export interface IStepsProps {
}
export interface StepItemState {
- uid: number | undefined
+ uid: number
currentStatus: string
setIndex: (val: number) => void
calcProgress: (status: string) => void
@@ -83,6 +83,8 @@ export interface StepItemState {
export interface IStepsInject {
props: IStepsProps
steps: Ref
+ addStep: (item: StepItemState) => void
+ removeStep: (uid: number) => void
}
defineOptions({
@@ -112,9 +114,7 @@ onMounted(() => {
})
onBeforeUnmount(() => {
- parent.steps.value = parent.steps.value.filter(
- (instance) => instance.uid !== currentInstance?.uid
- )
+ parent.removeStep(stepItemState.uid)
})
const currentStatus = computed(() => {
@@ -203,11 +203,11 @@ const updateStatus = (activeIndex: number) => {
}
const stepItemState = reactive({
- uid: computed(() => currentInstance?.uid),
+ uid: currentInstance!.uid,
currentStatus,
setIndex,
calcProgress,
})
-parent.steps.value = [...parent.steps.value, stepItemState]
+parent.addStep(stepItemState)
diff --git a/packages/components/steps/src/steps.vue b/packages/components/steps/src/steps.vue
index 492df29276..a6d0436993 100644
--- a/packages/components/steps/src/steps.vue
+++ b/packages/components/steps/src/steps.vue
@@ -5,12 +5,11 @@