vuematerial / vue-material

Vue.js Framework - ready-to-use Vue components with Material Design, free forever.
https://www.creative-tim.com/vuematerial
MIT License
9.88k stars 1.16k forks source link

[Md-stepper] Bug when staying on the route #2233

Open MirzetKameric opened 4 years ago

MirzetKameric commented 4 years ago

If in one of the steps you add beforeRouteLeave method to ask user are they sure they want to leave, and they click no (staying on the route), md-stepper still changes active class to the step user clicked.

I see there is a watcher on the route to sync active step to it.

if (this.mdSyncRoute) { this.$watch('$route', { deep: true, handler () { this.setActiveStepByRoute() } }) }

Issue with this is that route has not been changed, therefore this will not take place. But stepper has its own inner state management that changes the step to the one user clicked, regardless of route syncing and it calls this method.

setActiveStep (id) { if (this.mdLinear && !this.isPreviousStepperDone(id)) { return false } if (id !== this.MdSteppers.activeStep && (this.isStepperEditable(id) || !this.isStepperDone(id))) { this.setPreviousStepperAsDone(id) this.MdSteppers.activeStep = id this.$emit('md-changed', id) this.$emit('update:mdActiveStep', id) this.MdSteppers.items[id].error = null } }

Hacky solution I found is to put ref on stepper and call this setActiveStep method with proper step id.