Skip to content

Commit

Permalink
fix(tree): 兼容Firefox (#2697)
Browse files Browse the repository at this point in the history
  • Loading branch information
zyprepare committed Jan 3, 2024
1 parent 3caa7e5 commit b97e1f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .changeset/real-points-jump.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@hi-ui/tree": patch
---

fix: 修复编辑框内容无法选中问题
fix: 修复可拖拽模式下编辑框内容无法选中问题
15 changes: 11 additions & 4 deletions 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 Expand Up @@ -431,9 +441,6 @@ const EditableNodeInput = (props: EditableNodeInputProps) => {
value={inputValue}
onChange={handleChange}
onKeyDown={onKeydown}
// hotfix: https://github.com/XiaoMi/hiui/issues/2697
draggable
onDragStart={(evt) => evt.preventDefault()}
/>
<span className={`${prefixCls}__action`}>
<IconButton
Expand Down

0 comments on commit b97e1f7

Please sign in to comment.