Skip to content

Commit fadddc7

Browse files
committed
fix: Tree keyboard movement for child items that are expanded
The tree will now correctly not consider items visible if the direct parent is expanded, but a parent above is closed.
1 parent eef48dc commit fadddc7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/tree/src/useFlattenedTreeList.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,12 @@ export default function useFlattenedTreeList({
142142
return flattenedItems.reduce<ItemCollection>(
143143
(collection, item) => {
144144
const { parentId, itemId } = item;
145-
const isVisible =
146-
parentId === rootId ||
147-
(parentId !== null && expandedIds.includes(parentId));
145+
let isVisible = parentId === rootId;
146+
if (parentId !== null && expandedIds.includes(parentId)) {
147+
// need to also make sure that the parent is visible
148+
isVisible =
149+
(collection.itemRefs[parentId]?.visibleIndex ?? -1) !== -1;
150+
}
148151

149152
collection.itemRefs[itemId] = {
150153
id: item.id,

0 commit comments

Comments
 (0)