From c33de442a59d8c522faf1af8edd76731d7b3c577 Mon Sep 17 00:00:00 2001 From: Alla Doroshkevych Date: Wed, 28 Feb 2024 16:12:07 -0500 Subject: [PATCH 1/2] check if element exists before focusing added --- .../src/CompactInteractiveList.jsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/terra-compact-interactive-list/src/CompactInteractiveList.jsx b/packages/terra-compact-interactive-list/src/CompactInteractiveList.jsx index 6f4d8631c7d..5801a399c66 100644 --- a/packages/terra-compact-interactive-list/src/CompactInteractiveList.jsx +++ b/packages/terra-compact-interactive-list/src/CompactInteractiveList.jsx @@ -154,14 +154,16 @@ const CompactInteractiveList = (props) => { const focusCell = ({ row, cell }) => { // add 1 to the row number to accommodate for hidden header - const focusedCellElement = listRef.current.children[row + 1].children[cell]; - const interactiveChildren = getFocusableElements(focusedCellElement); - if (interactiveChildren?.length > 0 && interactiveChildren[0]) { - // currently a cell can have only one interact-able element in it, which gets auto-focused. - interactiveChildren[0].focus(); - } else { - // cell gets focus if there is no interact-able elements in it. - focusedCellElement.focus(); + const focusedCellElement = listRef.current?.children[row + 1]?.children[cell]; + if (focusedCellElement) { + const interactiveChildren = getFocusableElements(focusedCellElement); + if (interactiveChildren?.length > 0 && interactiveChildren[0]) { + // currently a cell can have only one interact-able element in it, which gets auto-focused. + interactiveChildren[0].focus(); + } else { + // cell gets focus if there is no interact-able elements in it. + focusedCellElement.focus(); + } } }; From 553a6f0cca24706d8c8cccca7002b50936d5fd58 Mon Sep 17 00:00:00 2001 From: Alla Doroshkevych Date: Wed, 28 Feb 2024 17:11:18 -0500 Subject: [PATCH 2/2] changelog updated --- packages/terra-compact-interactive-list/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/terra-compact-interactive-list/CHANGELOG.md b/packages/terra-compact-interactive-list/CHANGELOG.md index 1bff09ebc77..94f5dac4867 100644 --- a/packages/terra-compact-interactive-list/CHANGELOG.md +++ b/packages/terra-compact-interactive-list/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Fixed + * Added check for cell element existence before focusing. + ## 1.5.0 - (February 28, 2024) * Changed