Skip to content

Commit

Permalink
fix: prevent the tour of starting again when using arrow keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mmorainville committed Mar 13, 2018
1 parent a7cfbbd commit d7e8d42
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/components/VTour.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default {
name: {
type: String
},
customOptions: {
options: {
type: Object,
default: () => { return DEFAULT_OPTIONS }
}
Expand All @@ -55,7 +55,7 @@ export default {
mounted () {
this.$tours[this.name] = this
if (this.options.useKeyboardNavigation) {
if (this.customOptions.useKeyboardNavigation) {
window.addEventListener('keyup', e => {
// TODO: debug mode
// console.log('[Vue Tour] A keyup event occured:', e)
Expand All @@ -74,18 +74,19 @@ export default {
}
},
beforeDestroy () {
// Remove the keyup listener if it has been defined
if (this.options.useKeyboardNavigation) {
// Remove the keyup listener if it has been defined.
// Might have side-effects if the user already defined a listener on keyup.
if (this.customOptions.useKeyboardNavigation) {
window.removeEventListener('keyup')
}
},
computed: {
// Allow us to define custom options and merge them with the default options.
// Since options is a computed property, it is reactive and can be updated during runtime.
options () {
customOptions () {
return {
...DEFAULT_OPTIONS,
...this.customOptions
...this.options
}
},
// Return true if the tour is active, which means that there's a VStep displayed
Expand All @@ -107,13 +108,13 @@ export default {
// Wait for the DOM to be loaded, then start the tour
setTimeout(() => {
this.currentStep = 0
}, this.options.startTimeout)
}, this.customOptions.startTimeout)
},
previousStep () {
if (this.currentStep > 0) this.currentStep--
},
nextStep () {
if (this.currentStep < this.numberOfSteps - 1) this.currentStep++
if (this.currentStep < this.numberOfSteps - 1 && this.currentStep !== -1) this.currentStep++
},
stop () {
this.currentStep = -1
Expand Down

0 comments on commit d7e8d42

Please sign in to comment.