From b5a20e0a2c461d6bab44fe2cfb41cd6eb6b18cf9 Mon Sep 17 00:00:00 2001 From: melloware Date: Wed, 28 Feb 2024 09:00:42 -0500 Subject: [PATCH] Fix #6049: Tree lazy mode crash on arrow right --- components/lib/tree/Tree.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/components/lib/tree/Tree.js b/components/lib/tree/Tree.js index 6f5691cd69..3ec73d668f 100644 --- a/components/lib/tree/Tree.js +++ b/components/lib/tree/Tree.js @@ -62,11 +62,19 @@ export const Tree = React.memo( const event = childFocusEvent.current; const nodeElement = event.target.getAttribute('data-pc-section') === 'toggler' ? event.target.closest('[role="treeitem"]') : event.target; const listElement = nodeElement.children[1]; - const childElement = listElement.children[0]; - nodeElement.tabIndex = '-1'; - childElement.tabIndex = '0'; - childElement.focus(); + if (listElement) { + if (nodeElement) { + nodeElement.tabIndex = '-1'; + } + + const childElement = listElement.children[0]; + + if (childElement) { + childElement.tabIndex = '0'; + childElement.focus(); + } + } childFocusEvent.current = null; }