Skip to content

Commit

Permalink
fix(tree): 修复拖拽和编辑模式下保存时异常 (#3022)
Browse files Browse the repository at this point in the history
  • Loading branch information
zyprepare committed Oct 15, 2024
1 parent 6068023 commit 38986b2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions .changeset/gorgeous-jars-swim.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
---

fix(tree): 修复编辑模式下保存无效问题 (#3017)
fix(tree): 修复拖拽和编辑模式下保存时异常问题 (#3022)
8 changes: 7 additions & 1 deletion packages/ui/tree/src/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export const Tree = forwardRef<HTMLUListElement | null, TreeProps>(
iconRender,
onContextMenu,
expandOnSelect,
treeData,
}),
[
onNodeSelect,
Expand All @@ -211,6 +212,7 @@ export const Tree = forwardRef<HTMLUListElement | null, TreeProps>(
iconRender,
onContextMenu,
expandOnSelect,
treeData,
]
)

Expand Down Expand Up @@ -342,7 +344,11 @@ export interface TreeProps {
/**
* 节点结束拖拽时触发
*/
onDragEnd?: (evt: React.DragEvent, options: { dragNode: TreeNodeEventData }) => void
onDragEnd?: (
evt: React.DragEvent,
options: { dragNode: TreeNodeEventData },
treeData: TreeDataItem[]
) => void
/**
* 节点放开时触发,返回 true 表示允许更新拖拽后数据
*/
Expand Down
5 changes: 3 additions & 2 deletions packages/ui/tree/src/TreeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const TreeNode = forwardRef<HTMLLIElement | null, TreeNodeProps>((props,
expandedIcon: expandIconContext,
leafIcon: leafIconContext,
expandOnSelect,
treeData,
} = useTreeContext()

const collapsedIcon = collapseIconContext || collapseIconProp
Expand Down Expand Up @@ -118,9 +119,9 @@ export const TreeNode = forwardRef<HTMLLIElement | null, TreeNodeProps>((props,
setDirection(null)
setIsDragging(false)

onDragEndContextLatest(evt, { dragNode: eventNodeRef.current })
onDragEndContextLatest(evt, { dragNode: eventNodeRef.current }, treeData)
},
[onDragEndContextLatest, eventNodeRef, dragNodeRef]
[dragNodeRef, onDragEndContextLatest, eventNodeRef, treeData]
)

const onDragLeaveContextLatest = useLatestCallback(onDragLeaveContext)
Expand Down
9 changes: 7 additions & 2 deletions packages/ui/tree/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { createContext, useContext } from 'react'
import { TreeNodeEventData, TreeNodeDragDirection } from './types'
import { TreeNodeEventData, TreeNodeDragDirection, TreeDataItem } from './types'

interface TreeContext {
selectable?: boolean
Expand All @@ -8,7 +8,11 @@ interface TreeContext {
draggable?: boolean
dragNodeRef: React.MutableRefObject<TreeNodeEventData | null>
onDragStart?: (evt: React.DragEvent, options: { dragNode: TreeNodeEventData }) => void
onDragEnd?: (evt: React.DragEvent, options: { dragNode: TreeNodeEventData }) => void
onDragEnd?: (
evt: React.DragEvent,
options: { dragNode: TreeNodeEventData },
data: TreeDataItem[]
) => void
onDrop?: (
evt: React.DragEvent,
dragId: React.ReactText,
Expand Down Expand Up @@ -42,6 +46,7 @@ interface TreeContext {
onContextMenu?: (event: React.MouseEvent, node: TreeNodeEventData) => void
checkOnSelect: boolean
expandOnSelect?: boolean
treeData: TreeDataItem[]
}

const treeContext = createContext<TreeContext | null>(null)
Expand Down

0 comments on commit 38986b2

Please sign in to comment.