From 18ea76a434f69ec66268aaf8756a41978c9fdb5a Mon Sep 17 00:00:00 2001 From: Sugan G Date: Fri, 8 Mar 2024 15:44:40 +0530 Subject: [PATCH] [terra-worklist-data-grid] Fixes column index out of range for displayed columns (#2071) Co-authored-by: Sugan G --- packages/terra-data-grid/CHANGELOG.md | 3 +++ packages/terra-data-grid/src/DataGrid.jsx | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/terra-data-grid/CHANGELOG.md b/packages/terra-data-grid/CHANGELOG.md index 2efd8cfdf67..1766f28feeb 100644 --- a/packages/terra-data-grid/CHANGELOG.md +++ b/packages/terra-data-grid/CHANGELOG.md @@ -5,6 +5,9 @@ * Added * Added support for orange and green column highlighting. +* Fixed + * Fixes column index out of bounds in row selection mode. + ## 1.18.0 - (March 5, 2024) * Changed diff --git a/packages/terra-data-grid/src/DataGrid.jsx b/packages/terra-data-grid/src/DataGrid.jsx index b01dc41875f..41d3fb8f3a3 100644 --- a/packages/terra-data-grid/src/DataGrid.jsx +++ b/packages/terra-data-grid/src/DataGrid.jsx @@ -247,10 +247,12 @@ const DataGrid = forwardRef((props, ref) => { setFocusedRow(newRowIndex); setFocusedCol(newColIndex); - focusedCellRef.current = { - rowId: grid.current.rows[newRowIndex].getAttribute('data-row-id'), - columnId: displayedColumns[newColIndex].id, - }; + if (newColIndex < displayedColumns.length) { + focusedCellRef.current = { + rowId: grid.current.rows[newRowIndex].getAttribute('data-row-id'), + columnId: displayedColumns[newColIndex].id, + }; + } if (makeActiveElement) { let focusedCell;