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 | 171 | </div> |
| 172 | 172 | </TabPane> |
| 173 | 173 | </Tabs> |
| 174 | + <Tabs type="card"> | |
| 175 | + <TabPane label="标签一">标签一的内容</TabPane> | |
| 176 | + <TabPane label="标签二" disabled>标签二的内容</TabPane> | |
| 177 | + <TabPane label="标签三">标签三的内容</TabPane> | |
| 178 | + </Tabs> | |
| 174 | 179 | </div> |
| 175 | 180 | </template> |
| 176 | 181 | <script> | ... | ... |
src/components/tabs/tabs.vue
| ... | ... | @@ -43,7 +43,7 @@ |
| 43 | 43 | const currentIndex = list.findIndex(tab => tab.name === activeKey); |
| 44 | 44 | const nextIndex = (currentIndex + direction + list.length) % list.length; |
| 45 | 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 | 47 | else return nextTab; |
| 48 | 48 | }; |
| 49 | 49 | |
| ... | ... | @@ -237,8 +237,9 @@ |
| 237 | 237 | this.focusedKey = nextTab.name; |
| 238 | 238 | }, |
| 239 | 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 | 243 | [...this.$refs.panes.children].forEach((el, i) => { |
| 243 | 244 | if (nextIndex === i) { |
| 244 | 245 | [...el.children].forEach(child => child.style.display = 'block'); |
| ... | ... | @@ -411,6 +412,8 @@ |
| 411 | 412 | |
| 412 | 413 | this.mutationObserver.observe(hiddenParentNode, { attributes: true, childList: true, characterData: true, attributeFilter: ['style'] }); |
| 413 | 414 | } |
| 415 | + | |
| 416 | + this.handleTabKeyboardSelect(); | |
| 414 | 417 | }, |
| 415 | 418 | beforeDestroy() { |
| 416 | 419 | this.observer.removeListener(this.$refs.navWrap, this.handleResize); | ... | ... |