Correct logic for selecting by keyboard
This commit is contained in:
parent
2bf3e04753
commit
38ab744203
2 changed files with 40 additions and 16 deletions
|
@ -176,18 +176,39 @@
|
||||||
<TabPane label="标签二" disabled>标签二的内容</TabPane>
|
<TabPane label="标签二" disabled>标签二的内容</TabPane>
|
||||||
<TabPane label="标签三">标签三的内容</TabPane>
|
<TabPane label="标签三">标签三的内容</TabPane>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
<tabs v-model="name" type="card" @on-click="handleClick">
|
||||||
|
<tab-pane name="a" label="标签一">
|
||||||
|
<div>1</div>
|
||||||
|
</tab-pane>
|
||||||
|
<tab-pane name="b" label="标签二">
|
||||||
|
<div>2</div>
|
||||||
|
</tab-pane>
|
||||||
|
<tab-pane name="c" label="标签三">
|
||||||
|
<div>3</div>
|
||||||
|
</tab-pane>
|
||||||
|
<tab-pane name="d" label="标签四">
|
||||||
|
<div>4</div>
|
||||||
|
</tab-pane>
|
||||||
|
<tab-pane name="e" label="标签五">
|
||||||
|
<div>5</div>
|
||||||
|
</tab-pane>
|
||||||
|
</tabs>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
tabs: 2
|
tabs: 2,
|
||||||
|
name: 'b',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleTabsAdd () {
|
handleTabsAdd () {
|
||||||
this.tabs ++;
|
this.tabs ++;
|
||||||
|
},
|
||||||
|
handleClick (name) {
|
||||||
|
console.log(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,21 +237,9 @@
|
||||||
this.focusedKey = nextTab.name;
|
this.focusedKey = nextTab.name;
|
||||||
},
|
},
|
||||||
handleTabKeyboardSelect(){
|
handleTabKeyboardSelect(){
|
||||||
this.activeKey = this.focusedKey || 0;
|
const focused = this.focusedKey || 0;
|
||||||
const nextIndex = Math.max(this.navList.findIndex(tab => tab.name === this.focusedKey), 0);
|
const index = this.navList.findIndex(({name}) => name === focused);
|
||||||
|
this.handleChange(index);
|
||||||
[...this.$refs.panes.children].forEach((el, i) => {
|
|
||||||
if (nextIndex === i) {
|
|
||||||
[...el.children].forEach(child => child.style.display = 'block');
|
|
||||||
setTimeout(() => {
|
|
||||||
focusFirst(el, el);
|
|
||||||
}, transitionTime);
|
|
||||||
} else {
|
|
||||||
setTimeout(() => {
|
|
||||||
[...el.children].forEach(child => child.style.display = 'none');
|
|
||||||
}, transitionTime);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
handleRemove (index) {
|
handleRemove (index) {
|
||||||
const tabs = this.getTabs();
|
const tabs = this.getTabs();
|
||||||
|
@ -394,6 +382,21 @@
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.scrollToActiveTab();
|
this.scrollToActiveTab();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// update visibility
|
||||||
|
const nextIndex = Math.max(this.navList.findIndex(tab => tab.name === this.focusedKey), 0);
|
||||||
|
[...this.$refs.panes.children].forEach((el, i) => {
|
||||||
|
if (nextIndex === i) {
|
||||||
|
[...el.children].forEach(child => child.style.display = 'block');
|
||||||
|
setTimeout(() => {
|
||||||
|
focusFirst(el, el);
|
||||||
|
}, transitionTime);
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
|
[...el.children].forEach(child => child.style.display = 'none');
|
||||||
|
}, transitionTime);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue