Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tree): 修复拖拽模式下编辑框内容无法选中问题 #2702

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/gorgeous-timers-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

fix(tree): 修复编辑框内容无法选中问题
5 changes: 5 additions & 0 deletions .changeset/real-points-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/tree": patch
---

fix: 修复可拖拽模式下编辑框内容无法选中问题
12 changes: 11 additions & 1 deletion packages/ui/tree/src/use-tree-action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export const useTreeEditProps = <T extends EditableTreeProps>(
onDelete
)

const [editing, setEditing] = React.useState<boolean>(false)

const renderTitleWithEditable = (node: FlattedTreeNodeData, title?: React.ReactNode) => {
return (
<EditableTreeNodeTitle
Expand All @@ -120,6 +122,7 @@ export const useTreeEditProps = <T extends EditableTreeProps>(
focusTree={focusTree}
onExpand={tryToggleExpandedIds}
actionRender={actionRender}
onEditStatusChange={setEditing}
/>
)
}
Expand All @@ -138,6 +141,8 @@ export const useTreeEditProps = <T extends EditableTreeProps>(

const treeProps = {
...nativeTreeProps,
// hotfix: https://github.com/XiaoMi/hiui/issues/2697
draggable: editing ? false : nativeTreeProps.draggable,
fieldNames,
render: proxyTitleRender,
data: editable ? treeData : data,
Expand Down Expand Up @@ -194,11 +199,15 @@ export interface EditableTreeProps extends TreeProps {
}

const EditableTreeNodeTitle = (props: EditableTreeNodeTitleProps) => {
const { prefixCls, node, title, actionRender } = props
const { prefixCls, node, title, actionRender, onEditStatusChange } = props

// 如果是添加节点,则进入节点编辑临时态
const [editing, editingAction] = useToggle(() => node.raw.type === TreeNodeType.ADD || false)

React.useEffect(() => {
onEditStatusChange?.(editing)
}, [editing, onEditStatusChange])

if (editing) {
return <EditableNodeInput {...props} editingAction={editingAction} />
}
Expand Down Expand Up @@ -226,6 +235,7 @@ interface EditableTreeNodeTitleProps {
menuOptions?: TreeMenuActionOption[] | ((node: FlattedTreeNodeData) => TreeMenuActionOption[])
focusTree: () => void
actionRender?: (node: FlattedTreeNodeData, editActions: TreeEditActions) => React.ReactNode | null
onEditStatusChange?: (editing: boolean) => void
}

const EditableNodeMenu = (props: EditableNodeMenuProps) => {
Expand Down