Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/tree/src/tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@
this.treeItems[0] && this.treeItems[0].setAttribute('tabindex', 0);
},

handelKeydown(ev) {
handleKeydown(ev) {
const currentItem = ev.target;
if (currentItem.className.indexOf('el-tree-node') === -1) return;
ev.preventDefault();
const keyCode = ev.keyCode;
this.treeItems = this.$el.querySelectorAll('.is-focusable[role=treeitem]');
const currentIndex = this.treeItemArray.indexOf(currentItem);
let nextIndex;
if ([38, 40].indexOf(keyCode) > -1) { // up、down
ev.preventDefault();
if (keyCode === 38) { // up
nextIndex = currentIndex !== 0 ? currentIndex - 1 : 0;
} else {
Expand All @@ -306,10 +306,12 @@
this.treeItemArray[nextIndex].focus(); // 选中
}
if ([37, 39].indexOf(keyCode) > -1) { // left、right 展开
ev.preventDefault();
currentItem.click(); // 选中
}
const hasInput = currentItem.querySelector('[type="checkbox"]');
if ([13, 32].indexOf(keyCode) > -1 && hasInput) { // space enter选中checkbox
ev.preventDefault();
hasInput.click();
}
}
Expand Down Expand Up @@ -476,7 +478,7 @@

mounted() {
this.initTabIndex();
this.$el.addEventListener('keydown', this.handelKeydown);
this.$el.addEventListener('keydown', this.handleKeydown);
},

updated() {
Expand Down