This commit is contained in:
oneao committed 2026-10-09 22:05:02 +08:00
1 parent 0be0b0767a
commit 5f28a10d89
852 files changed
+8962 -111755

No files matched your search

+26 -20
View File
@@ -10,9 +10,11 @@ import {
watch,
type VNode,
} from 'vue'
import { useDirection } from '../_composables/useDirection'
import { useLocale } from '../_composables/useLocale'
import { useNamespace } from '../_composables/useNamespace'
import { usePopupContainer } from '../_composables/usePopupContainer'
import { horizontalArrowStep } from '../_utils/direction'
import { computePosition, type RectLike } from '../_utils/position'
import { nextZIndex, releaseZIndex } from '../_utils/z-index'
import { treeContextKey } from './context'
@@ -92,6 +94,7 @@ const emit = defineEmits<{
}>()
const { b, e, is } = useNamespace('tree')
const textDirection = useDirection()
const locale = useLocale()
const teleportTo = usePopupContainer()
@@ -437,28 +440,31 @@ function onKeydown(event: KeyboardEvent) {
moveActive(-1)
break
case 'ArrowRight':
event.preventDefault()
if (!effectiveExpanded.value.has(key)) toggleExpand(node, key)
else {
const children = getNodeChildren(node, fieldNames.value)
const firstChild = children?.[0]
if (firstChild) {
const childKey = String(getNodeKey(firstChild, fieldNames.value))
activeKey.value = childKey
nextTick(() => nodeEls.get(childKey)?.focus())
}
}
break
case 'ArrowLeft': {
event.preventDefault()
if (effectiveExpanded.value.has(key)) {
toggleExpand(node, key)
break
}
const parent = flat.value.parentMap.get(key)
if (parent) {
activeKey.value = parent
nextTick(() => nodeEls.get(parent)?.focus())
// 朝行内结束方向(LTR 右 / RTL 左)= 展开或进第一个子节点;反向 = 收起或回父节点。
// 树的缩进与展开箭头都跟着方向走,键盘语义必须与画面一致。
if (horizontalArrowStep(event.key, textDirection.value) === 1) {
if (!effectiveExpanded.value.has(key)) toggleExpand(node, key)
else {
const children = getNodeChildren(node, fieldNames.value)
const firstChild = children?.[0]
if (firstChild) {
const childKey = String(getNodeKey(firstChild, fieldNames.value))
activeKey.value = childKey
nextTick(() => nodeEls.get(childKey)?.focus())
}
}
} else {
if (effectiveExpanded.value.has(key)) {
toggleExpand(node, key)
break
}
const parent = flat.value.parentMap.get(key)
if (parent) {
activeKey.value = parent
nextTick(() => nodeEls.get(parent)?.focus())
}
}
break
}