2
0
mirror of https://github.com/tenrok/vue-form-wizard.git synced 2026-06-23 01:00:32 +03:00

#46 Handle keyboard navigation the same way as clicking on steps

This commit is contained in:
cristijora
2017-09-27 19:19:32 +03:00
parent 7c64ff4bd9
commit 1e6aa85bd9
2 changed files with 7 additions and 12 deletions
+6 -11
View File
@@ -21,7 +21,7 @@
<wizard-step :tab="tab" <wizard-step :tab="tab"
:step-size="stepSize" :step-size="stepSize"
@click.native="navigateToTab(index)" @click.native="navigateToTab(index)"
@keyup.enter.native="navigateOrGoToNext(index)" @keyup.enter.native="navigateToTab(index)"
:transition="transition" :transition="transition"
:index="index"> :index="index">
</wizard-step> </wizard-step>
@@ -213,7 +213,7 @@
}, },
addTab (item) { addTab (item) {
const index = this.$slots.default.indexOf(item.$vnode) const index = this.$slots.default.indexOf(item.$vnode)
item.tabId = `t-${item.title}${index}` item.tabId = `t-${item.title.replace(/ /g, '')}${index}`
this.tabs.splice(index, 0, item) this.tabs.splice(index, 0, item)
// if a step is added before the current one, go to it // if a step is added before the current one, go to it
if (index < this.activeTabIndex + 1) { if (index < this.activeTabIndex + 1) {
@@ -259,13 +259,6 @@
} }
return index <= this.maxStep return index <= this.maxStep
}, },
navigateOrGoToNext (index) {
if (!this.navigateToTab(index)) {
for (let i = this.activeTabIndex; i < index; i++) {
this.nextTab()
}
}
},
nextTab () { nextTab () {
let cb = () => { let cb = () => {
if (this.activeTabIndex < this.tabCount - 1) { if (this.activeTabIndex < this.tabCount - 1) {
@@ -292,8 +285,10 @@
focusNextTab () { focusNextTab () {
let tabIndex = getFocusedTabIndex(this.tabs) let tabIndex = getFocusedTabIndex(this.tabs)
if (tabIndex !== -1 && tabIndex < this.tabs.length - 1) { if (tabIndex !== -1 && tabIndex < this.tabs.length - 1) {
let toFocusId = this.tabs[tabIndex + 1].tabId let tabToFocus = this.tabs[tabIndex + 1]
findElementAndFocus(toFocusId) if (tabToFocus.checked) {
findElementAndFocus(tabToFocus.tabId)
}
} }
}, },
focusPrevTab () { focusPrevTab () {
+1 -1
View File
@@ -4,7 +4,7 @@
<a> <a>
<div class="wizard-icon-circle md" <div class="wizard-icon-circle md"
role="tab" role="tab"
tabindex="0" :tabindex="tab.checked ? 0 : -1"
:id="tab.tabId" :id="tab.tabId"
:aria-controls="tab.title" :aria-controls="tab.title"
:aria-disabled="tab.active" :aria-disabled="tab.active"