Replies: 1 comment
-
Would appreciate help with this. For more context, it seems internally the library focuses the first child of the "root" whenever focusedItem is null (when using focusedItem inside the view state). autoFocus=false does not seem to work. useEffect(() => {
if (selectedItems.length > 0) {
setFocusedItem(selectedItems[0]);
} else {
const firstItem = treeData.items['root'].children[1];
setFocusedItem(() => {
return firstItem;
});
// Ensure the first item is focused in the tree
if (treeRef.current) {
treeRef.current.focusItem(firstItem, 'file-tree', true);
}
}
}, []); I have clicking outside to de-focus implemented like so: useClickOutside(treeContainerRef, (event) => {
if (!treeContainerRef.current) return;
const clickedElement = event.target;
if (isUserClickWithinSafeZoneToNotClearFocus(clickedElement)) {
return;
}
setFocusedItem(null);
}); If I click outside, to de-focus, internally the first item gets focused again. If I click on the first item, it does not trigger the onFocusItem={(item) => setFocusedItem(item.index)} function, so the focusedItem state remains null until I click on any other item and back on the first item. Is there any way to disable the internal focusing and only let the view state control it? Or some other way to sync internal and external states? |
Beta Was this translation helpful? Give feedback.
-
Hello! I am using the ControlledEnvironment tree and am completely stumped when it comes to focus handling. I've dug around in the data structures/functions that are exposed through the refs, but can't figure this out. I am trying to manage the focused item to apply state to it when the item is focused and remove state when not. I am the focusedItem state with a useClickOutside hook. Although the focusedItem state gets nullified when user clicks outside, the library just makes the first item in the tree structure focused even when focusedItem is undefined. I can't seem to find a solution to this. Would anyone have any suggestions for me? Greatly appreciate any help!
Beta Was this translation helpful? Give feedback.
All reactions