From eb102b35c2cb0e0f744d498c76815b852e2cee92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20R=C3=B6hl?= Date: Fri, 30 Dec 2022 23:37:54 +0100 Subject: [PATCH 1/4] =?UTF-8?q?=C3=ADmprove,=20do=20not=20reset=20active?= =?UTF-8?q?=20item=20on=20mouse=20move?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ...as described in #689 --- src/NodeList.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/NodeList.tsx b/src/NodeList.tsx index 525bfd47..ad432aa5 100644 --- a/src/NodeList.tsx +++ b/src/NodeList.tsx @@ -357,9 +357,6 @@ const NodeList = React.forwardRef>((props, ref) onMotionStart={onListChangeStart} onMotionEnd={onMotionEnd} treeNodeRequiredProps={treeNodeRequiredProps} - onMouseMove={() => { - onActiveChange(null); - }} /> ); }} From 631e9e82bbbb79c45e2caa3e9f98b6e67f1cd0a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20R=C3=B6hl?= Date: Fri, 30 Dec 2022 23:40:44 +0100 Subject: [PATCH 2/4] change, explicitly set focus if focused changed --- src/NodeList.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/NodeList.tsx b/src/NodeList.tsx index ad432aa5..2c042028 100644 --- a/src/NodeList.tsx +++ b/src/NodeList.tsx @@ -169,6 +169,7 @@ const NodeList = React.forwardRef>((props, ref) // =============================== Ref ================================ const listRef = React.useRef(null); const indentMeasurerRef = React.useRef(null); + const inputRef = React.useRef(null); React.useImperativeHandle(ref, () => ({ scrollTo: scroll => { listRef.current.scrollTo(scroll); @@ -252,6 +253,12 @@ const NodeList = React.forwardRef>((props, ref) } }, [dragging]); + React.useEffect(() => { + if (focused && inputRef.current) { + inputRef.current.focus(); + } + }, [focused]); + const mergedData = motion ? transitionData : data; const treeNodeRequiredProps = { @@ -281,6 +288,7 @@ const NodeList = React.forwardRef>((props, ref) tabIndex={focusable !== false ? tabIndex : null} onKeyDown={onKeyDown} onFocus={onFocus} + ref={inputRef} onBlur={onBlur} value="" onChange={noop} From bdceff90cd5a044dacc524cad0ca3323fbd7943b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20R=C3=B6hl?= Date: Fri, 30 Dec 2022 23:45:05 +0100 Subject: [PATCH 3/4] ensure focused on select or check --- src/Tree.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Tree.tsx b/src/Tree.tsx index c51dff53..a42f36ad 100644 --- a/src/Tree.tsx +++ b/src/Tree.tsx @@ -857,7 +857,7 @@ class Tree extends Rea }) .filter(node => node); - this.setUncontrolledState({ selectedKeys }); + this.setUncontrolledState({ selectedKeys, focused: true }); onSelect?.(selectedKeys, { event: 'select', @@ -940,6 +940,7 @@ class Tree extends Rea this.setUncontrolledState( { checkedKeys, + focused: true, }, false, { From 7399b8388e44e2e45aa043279172fdd62354aabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20R=C3=B6hl?= Date: Fri, 30 Dec 2022 23:46:10 +0100 Subject: [PATCH 4/4] update active item to selected/checked on --- src/Tree.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Tree.tsx b/src/Tree.tsx index a42f36ad..abae0fd5 100644 --- a/src/Tree.tsx +++ b/src/Tree.tsx @@ -858,6 +858,7 @@ class Tree extends Rea .filter(node => node); this.setUncontrolledState({ selectedKeys, focused: true }); + this.onActiveChange(key) onSelect?.(selectedKeys, { event: 'select', @@ -947,6 +948,7 @@ class Tree extends Rea halfCheckedKeys, }, ); + this.onActiveChange(key) } onCheck?.(checkedObj, eventObj as CheckInfo);