Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

[terra-data-grid] refactor setFocusedRowCol method in DataGrid.jsx #2076

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
771 changes: 392 additions & 379 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
"terra-enzyme-intl": "3",
"webpack": "5",
"webpack-cli": "4",
"webpack-dev-server": "^4",
"webpack-merge": "^5",
"webpack-dev-server": "4",
"webpack-merge": "5",
"xfc": "1"
},
"scripts": {
Expand Down
44 changes: 26 additions & 18 deletions packages/terra-data-grid/src/DataGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,30 +254,38 @@ const DataGrid = forwardRef((props, ref) => {
};
}

if (makeActiveElement) {
let focusedCell;
if (isSection(newRowIndex)) {
[focusedCell] = grid.current.rows[newRowIndex].cells;
if (!makeActiveElement) {
return;
}

if (!focusedCell.hasAttribute('tabindex')) {
focusedCell = grid.current.rows[newRowIndex].querySelector('button');
}
} else {
// Set focus on input field (checkbox) of row selection cells.
focusedCell = grid.current.rows[newRowIndex].cells[newColIndex];
if (isRowSelectionCell(newColIndex) && focusedCell.getElementsByTagName('input').length > 0) {
[focusedCell] = focusedCell.getElementsByTagName('input');
}
let focusedCell;
if (isSection(newRowIndex)) {
[focusedCell] = grid.current.rows[newRowIndex].cells;

// Set focus to column header button, if it exists
const isHeaderRow = (newRowIndex === 0 || (hasColumnHeaderActions && newRowIndex === 1));
if (isHeaderRow && !focusedCell.hasAttribute('tabindex')) {
focusedCell = focusedCell.querySelector('[role="button"]') || focusedCell.querySelector('button');
}
if (!focusedCell.hasAttribute('tabindex')) {
focusedCell = grid.current.rows[newRowIndex].querySelector('button');
}
focusedCell?.focus();
return;
}

// Set focus on input field (checkbox) of row selection cells.
focusedCell = grid.current.rows[newRowIndex].cells[newColIndex];
if (isRowSelectionCell(newColIndex) && focusedCell.getElementsByTagName('input').length > 0) {
[focusedCell] = focusedCell.getElementsByTagName('input');
focusedCell?.focus();
return;
}

// Set focus to column header button, if it exists
const isHeaderRow = (newRowIndex === 0 || (hasColumnHeaderActions && newRowIndex === 1));
if (isHeaderRow && !focusedCell.hasAttribute('tabindex')) {
focusedCell = focusedCell.querySelector('[role="button"]') || focusedCell.querySelector('button');
focusedCell?.focus();
return;
}

focusedCell?.focus();
}, [displayedColumns, isSection, isRowSelectionCell, hasColumnHeaderActions]);

// The focus is handled by the DataGrid. However, there are times
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading