Commit 45dbc6fdea70835d638921e7583c8fcb7829c33e
1 parent
7fa3f9ef
Correct disabled forward navigation
Showing
2 changed files
with
11 additions
and
3 deletions
Show diff stats
examples/routers/tabs.vue
@@ -171,6 +171,11 @@ | @@ -171,6 +171,11 @@ | ||
171 | </div> | 171 | </div> |
172 | </TabPane> | 172 | </TabPane> |
173 | </Tabs> | 173 | </Tabs> |
174 | + <Tabs type="card"> | ||
175 | + <TabPane label="标签一">标签一的内容</TabPane> | ||
176 | + <TabPane label="标签二" disabled>标签二的内容</TabPane> | ||
177 | + <TabPane label="标签三">标签三的内容</TabPane> | ||
178 | + </Tabs> | ||
174 | </div> | 179 | </div> |
175 | </template> | 180 | </template> |
176 | <script> | 181 | <script> |
src/components/tabs/tabs.vue
@@ -43,7 +43,7 @@ | @@ -43,7 +43,7 @@ | ||
43 | const currentIndex = list.findIndex(tab => tab.name === activeKey); | 43 | const currentIndex = list.findIndex(tab => tab.name === activeKey); |
44 | const nextIndex = (currentIndex + direction + list.length) % list.length; | 44 | const nextIndex = (currentIndex + direction + list.length) % list.length; |
45 | const nextTab = list[nextIndex]; | 45 | const nextTab = list[nextIndex]; |
46 | - if (nextTab.disabled) return getNextTab(list, nextTab, direction, countDisabledAlso); | 46 | + if (nextTab.disabled) return getNextTab(list, nextTab.name, direction, countDisabledAlso); |
47 | else return nextTab; | 47 | else return nextTab; |
48 | }; | 48 | }; |
49 | 49 | ||
@@ -237,8 +237,9 @@ | @@ -237,8 +237,9 @@ | ||
237 | this.focusedKey = nextTab.name; | 237 | this.focusedKey = nextTab.name; |
238 | }, | 238 | }, |
239 | handleTabKeyboardSelect(){ | 239 | handleTabKeyboardSelect(){ |
240 | - this.activeKey = this.focusedKey; | ||
241 | - const nextIndex = this.navList.findIndex(tab => tab.name === this.focusedKey); | 240 | + this.activeKey = this.focusedKey || 0; |
241 | + const nextIndex = Math.max(this.navList.findIndex(tab => tab.name === this.focusedKey), 0); | ||
242 | + | ||
242 | [...this.$refs.panes.children].forEach((el, i) => { | 243 | [...this.$refs.panes.children].forEach((el, i) => { |
243 | if (nextIndex === i) { | 244 | if (nextIndex === i) { |
244 | [...el.children].forEach(child => child.style.display = 'block'); | 245 | [...el.children].forEach(child => child.style.display = 'block'); |
@@ -411,6 +412,8 @@ | @@ -411,6 +412,8 @@ | ||
411 | 412 | ||
412 | this.mutationObserver.observe(hiddenParentNode, { attributes: true, childList: true, characterData: true, attributeFilter: ['style'] }); | 413 | this.mutationObserver.observe(hiddenParentNode, { attributes: true, childList: true, characterData: true, attributeFilter: ['style'] }); |
413 | } | 414 | } |
415 | + | ||
416 | + this.handleTabKeyboardSelect(); | ||
414 | }, | 417 | }, |
415 | beforeDestroy() { | 418 | beforeDestroy() { |
416 | this.observer.removeListener(this.$refs.navWrap, this.handleResize); | 419 | this.observer.removeListener(this.$refs.navWrap, this.handleResize); |