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

[terra-data-grid] Update to automatically focus on single buttons or hyperlinks in cells #2066

Merged
merged 45 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
483ef99
updated cell focus example
sdadn Mar 4, 2024
4cc4422
Merge branch 'main' into update-cell-focus
sdadn Mar 4, 2024
9b485d3
working prototype
sdadn Mar 4, 2024
6a7216a
removed comments
sdadn Mar 5, 2024
a9fd1d8
updated tests
sdadn Mar 5, 2024
fd49e2d
updated tests
sdadn Mar 5, 2024
1db3e23
updated snapshots
sdadn Mar 5, 2024
f689fa9
updated tests
sdadn Mar 5, 2024
fd764d6
updated documentation
sdadn Mar 5, 2024
103f473
updated tests
sdadn Mar 5, 2024
c90ae90
linter fixes
sdadn Mar 5, 2024
6ca845d
Update packages/terra-framework-docs/src/terra-dev-site/doc/data-grid…
sdadn Mar 6, 2024
7000de9
removed logic from cell.jsx
sdadn Mar 6, 2024
3d19b39
removed extra file
sdadn Mar 6, 2024
ac99b8a
removed extra import
sdadn Mar 6, 2024
8fd0044
working logic in datagrid
sdadn Mar 6, 2024
a6e5af7
Merge branch 'update-cell-focus' of github.com:cerner/terra-framework…
sdadn Mar 6, 2024
85171e5
linter fixes
sdadn Mar 6, 2024
812ad7b
Revert "removed logic from cell.jsx"
sdadn Mar 6, 2024
3d35420
cleaned up code
sdadn Mar 6, 2024
d0785cb
Merge branch 'main' into update-cell-focus
sdadn Mar 7, 2024
4adacb2
fixed wdio tests
sdadn Mar 7, 2024
e6d434c
CHANGELOG updates
sdadn Mar 7, 2024
881b0fa
Merge branch 'main' into update-cell-focus
sdadn Mar 7, 2024
d86a316
Update DataGrid.jsx
sdadn Mar 7, 2024
c407fea
updated query selector
sdadn Mar 7, 2024
e42511d
updated Cell.jsx
sdadn Mar 7, 2024
4fb0196
Merge branch 'update-cell-focus' of github.com:cerner/terra-framework…
sdadn Mar 7, 2024
060a88a
updated selector and linter fixes
sdadn Mar 7, 2024
29763c1
updated logic
sdadn Mar 8, 2024
542a02a
Merge branch 'main' into update-cell-focus
sdadn Mar 8, 2024
0ac39e8
test change
sdadn Mar 8, 2024
920d723
Revert "test change"
sdadn Mar 8, 2024
351c230
updated package-lock
sdadn Mar 8, 2024
b61f6ad
Update data-grid-spec.js
sdadn Mar 11, 2024
f8282df
Merge branch 'main' into update-cell-focus
sdadn Mar 13, 2024
804452d
merged code with main
sdadn Mar 13, 2024
6e3d10a
updated package-lock
sdadn Mar 13, 2024
8142d5f
fixed failing tests
sdadn Mar 13, 2024
68ae088
updated code
sdadn Mar 13, 2024
675f968
Merge branch 'main' into update-cell-focus
sdadn Mar 14, 2024
35f647d
Merge branch 'main' into update-cell-focus
sdadn Mar 14, 2024
c509669
updated wdio snapshots
sdadn Mar 14, 2024
48cea1c
Merge branch 'update-cell-focus' of github.com:cerner/terra-framework…
sdadn Mar 14, 2024
d5c289b
Merge branch 'main' into update-cell-focus
sdadn Mar 14, 2024
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
154 changes: 77 additions & 77 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/terra-data-grid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* Added
* Added `event` object to `onCellSelect` callback.

* Changed
* Updated focus behavior so that cells with only a button or hyperlink will focus on those components directly without need for dive-in or focus trap.

## 1.19.0 - (March 8, 2024)

* Added
Expand Down
29 changes: 22 additions & 7 deletions packages/terra-data-grid/src/DataGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import React, {
import PropTypes from 'prop-types';
import classNames from 'classnames/bind';
import * as KeyCode from 'keycode-js';

import Table, {
GridConstants, GridContext, sectionShape, rowShape, columnShape, validateRowHeaderIndex, hasColumnActions, ColumnHighlightColor,
} from 'terra-table';
import getFocusableElements from 'terra-table/lib/utils/focusManagement';
import VisuallyHiddenText from 'terra-visually-hidden-text';
import WorklistDataGridUtils from './utils/WorklistDataGridUtils';

import styles from './DataGrid.module.scss';
import './_elementPolyfill';

Expand Down Expand Up @@ -260,6 +263,7 @@ const DataGrid = forwardRef((props, ref) => {
}

let focusedCell;

if (isSection(newRowIndex)) {
[focusedCell] = grid.current.rows[newRowIndex].cells;

Expand All @@ -270,18 +274,29 @@ const DataGrid = forwardRef((props, ref) => {
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');

// If there are multiple focusable elements, set focus on the cell
if (getFocusableElements(focusedCell).length > 1) {
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');
// Check if cell is in header row (for focusing on resize handles)
const isHeaderRow = newRowIndex === 0 || (hasColumnHeaderActions && newRowIndex === 1);

// Set focus to a single header button or hyperlink if they are the only content in cell
const cellButtonOrHyperlink = focusedCell.querySelector('a, button');
if ((isHeaderRow && !focusedCell.hasAttribute('tabindex')) || cellButtonOrHyperlink) {
focusedCell = focusedCell.querySelector('a, button, [role="button"]');
focusedCell?.focus();
return;
}

// Set focus on input field (checkbox) of row selection cells.
const rowSelectionCheckbox = focusedCell.querySelector('input');
if (isRowSelectionCell(newColIndex) && rowSelectionCheckbox) {
focusedCell = rowSelectionCheckbox;
focusedCell?.focus();
return;
}
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
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
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading