Skip to content

Commit

Permalink
fix: tree keyCode to key
Browse files Browse the repository at this point in the history
  • Loading branch information
Lydanne committed Sep 24, 2020
1 parent 52d6d7a commit 157b543
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/tree/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ function useKeyDown() {
const handleKeydown = (ev) => {
const currentItem = ev.target
if (currentItem.className.indexOf('el-tree-node') === -1) return
const keyCode = ev.keyCode
const { key } = ev
const treeItems = ctx.$el.querySelectorAll('.is-focusable[role=TreeNode]')
const treeItemArray = Array.prototype.slice.call(treeItems)
const currentIndex = treeItemArray.indexOf(currentItem)
let nextIndex
if ([38, 40].indexOf(keyCode) > -1) {
if (['ArrowUp', 'ArrowDown'].indexOf(key) > -1) {
// up、down
ev.preventDefault()
if (keyCode === 38) {
if (key === 'ArrowUp') {
// up
nextIndex = currentIndex !== 0 ? currentIndex - 1 : 0
} else {
Expand All @@ -262,16 +262,16 @@ function useKeyDown() {
}
treeItemArray[nextIndex].focus() // 选中
}
if ([37, 39].indexOf(keyCode) > -1) {
if (['ArrowLeft', 'ArrowRight'].indexOf(key) > -1) {
// left、right 展开
ev.preventDefault()
currentItem.click() // 选中
ev.preventDefault()
}
const hasInput = currentItem.querySelector('[type="checkbox"]')
if ([13, 32].indexOf(keyCode) > -1 && hasInput) {
if (['Enter', 'Space'].indexOf(key) > -1 && hasInput) {
// space enter选中checkbox
ev.preventDefault()
hasInput.click()
ev.preventDefault()
}
}
Expand Down

0 comments on commit 157b543

Please sign in to comment.