Skip to content

Commit bafee9c

Browse files
committed
feat(Stepper): add lockOnComplete prop
1 parent b7562ef commit bafee9c

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/content/Components/Stepper/Stepper.vue

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@click="() => handleStepClick(index + 1)"
1515
:class="[
1616
'relative outline-none flex h-8 w-8 items-center justify-center rounded-full font-semibold',
17-
isCompleted ? 'cursor-default' : 'cursor-pointer'
17+
isCompleted && lockOnComplete ? 'cursor-default' : 'cursor-pointer'
1818
]"
1919
:style="getStepIndicatorStyle(index + 1)"
2020
>
@@ -154,6 +154,7 @@ interface StepperProps {
154154
nextButtonText?: string;
155155
disableStepIndicators?: boolean;
156156
renderStepIndicator?: Component;
157+
lockOnComplete?: boolean;
157158
}
158159
159160
const props = withDefaults(defineProps<StepperProps>(), {
@@ -169,7 +170,8 @@ const props = withDefaults(defineProps<StepperProps>(), {
169170
backButtonText: 'Back',
170171
nextButtonText: 'Continue',
171172
disableStepIndicators: false,
172-
renderStepIndicator: undefined
173+
renderStepIndicator: undefined,
174+
lockOnComplete: true
173175
});
174176
175177
const slots = useSlots();
@@ -212,15 +214,15 @@ const getStepContentExit = () => ({
212214
});
213215
214216
const handleStepClick = (step: number) => {
215-
if (isCompleted.value) return;
217+
if (isCompleted.value && props.lockOnComplete) return;
216218
if (!props.disableStepIndicators) {
217219
direction.value = step > currentStep.value ? 1 : -1;
218220
updateStep(step);
219221
}
220222
};
221223
222224
const handleCustomStepClick = (clicked: number) => {
223-
if (isCompleted.value) return;
225+
if (isCompleted.value && props.lockOnComplete) return;
224226
if (clicked !== currentStep.value && !props.disableStepIndicators) {
225227
direction.value = clicked > currentStep.value ? 1 : -1;
226228
updateStep(clicked);
@@ -259,12 +261,18 @@ const handleComplete = () => {
259261
props.onFinalStepCompleted?.();
260262
};
261263
262-
watch(currentStep, newStep => {
263-
props.onStepChange?.(newStep);
264-
if (!isCompleted.value) {
265-
measureHeight();
264+
watch(
265+
currentStep,
266+
(newStep, oldStep) => {
267+
props.onStepChange?.(newStep);
268+
if (newStep !== oldStep && !isCompleted.value) {
269+
nextTick(measureHeight);
270+
} else if (!props.lockOnComplete && isCompleted.value) {
271+
isCompleted.value = false;
272+
nextTick(measureHeight);
273+
}
266274
}
267-
});
275+
);
268276
269277
onMounted(() => {
270278
if (props.initialStep !== 1) {

src/demo/Components/StepperDemo.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
:on-final-step-completed="handleFinalStepCompleted"
2222
:next-button-props="{ disabled: step === 3 && !name }"
2323
:disable-step-indicators="step === 3 && !name"
24+
:lock-on-complete="false"
2425
back-button-text="Previous"
2526
next-button-text="Next"
2627
>
@@ -170,6 +171,12 @@ const propData = [
170171
type: '(props: RenderStepIndicatorProps) => VNode',
171172
default: 'undefined',
172173
description: 'Renders a custom step indicator component.'
174+
},
175+
{
176+
name: 'lockOnComplete',
177+
type: 'boolean',
178+
default: 'false',
179+
description: 'Prevents returning to previous steps after completing the stepper.'
173180
}
174181
];
175182

0 commit comments

Comments
 (0)