Skip to content
Open
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
11 changes: 8 additions & 3 deletions src/NodeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ const NodeList = React.forwardRef<NodeListRef, NodeListProps<any>>((props, ref)
// =============================== Ref ================================
const listRef = React.useRef<ListRef>(null);
const indentMeasurerRef = React.useRef<HTMLDivElement>(null);
const inputRef = React.useRef<HTMLInputElement>(null);
React.useImperativeHandle(ref, () => ({
scrollTo: scroll => {
listRef.current.scrollTo(scroll);
Expand Down Expand Up @@ -252,6 +253,12 @@ const NodeList = React.forwardRef<NodeListRef, NodeListProps<any>>((props, ref)
}
}, [dragging]);

React.useEffect(() => {
if (focused && inputRef.current) {
inputRef.current.focus();
}
}, [focused]);

const mergedData = motion ? transitionData : data;

const treeNodeRequiredProps = {
Expand Down Expand Up @@ -281,6 +288,7 @@ const NodeList = React.forwardRef<NodeListRef, NodeListProps<any>>((props, ref)
tabIndex={focusable !== false ? tabIndex : null}
onKeyDown={onKeyDown}
onFocus={onFocus}
ref={inputRef}
onBlur={onBlur}
value=""
onChange={noop}
Expand Down Expand Up @@ -357,9 +365,6 @@ const NodeList = React.forwardRef<NodeListRef, NodeListProps<any>>((props, ref)
onMotionStart={onListChangeStart}
onMotionEnd={onMotionEnd}
treeNodeRequiredProps={treeNodeRequiredProps}
onMouseMove={() => {
onActiveChange(null);
}}
/>
);
}}
Expand Down
5 changes: 4 additions & 1 deletion src/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,8 @@ class Tree<TreeDataType extends DataNode | BasicDataNode = DataNode> extends Rea
})
.filter(node => node);

this.setUncontrolledState({ selectedKeys });
this.setUncontrolledState({ selectedKeys, focused: true });
this.onActiveChange(key)

onSelect?.(selectedKeys, {
event: 'select',
Expand Down Expand Up @@ -940,12 +941,14 @@ class Tree<TreeDataType extends DataNode | BasicDataNode = DataNode> extends Rea
this.setUncontrolledState(
{
checkedKeys,
focused: true,
},
false,
{
halfCheckedKeys,
},
);
this.onActiveChange(key)
}

onCheck?.(checkedObj, eventObj as CheckInfo<TreeDataType>);
Expand Down