Skip to content

Commit 108ede5

Browse files
danilsomsikovDevtools-frontend LUCI CQ
authored andcommitted
Fix data grid selection with keyboard navigation
1) Ensure only one row is highlighted when using keyboard navigation Currently keyboard navigation doesn't change activeElement, but sets 'selected' CSS class, which can results in one row highlighted due to the `:focus-within` rule and the other due to the `.selected` rule 2) Do not reset focus on keydown if the data grid is in the shadow root Currently we check if `document.activeElement` is in the data grid's subtree, but `document.activeElement` might be the shadow host of the data grid. Bug: 394287937 Change-Id: If779219871d1e076e0b3cbf937cf2dae577058f2 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6226108 Reviewed-by: Kim-Anh Tran <[email protected]> Auto-Submit: Danil Somsikov <[email protected]> Commit-Queue: Kim-Anh Tran <[email protected]>
1 parent bafe6ca commit 108ede5

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

front_end/ui/legacy/components/data_grid/DataGrid.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,8 @@ export class DataGridImpl<T> extends Common.ObjectWrapper.ObjectWrapper<EventTyp
12311231
nextSelectedNode.select();
12321232
}
12331233

1234-
if (handled && this.element !== document.activeElement && !this.element.contains(document.activeElement)) {
1234+
const activeElement = (Platform.DOMUtilities.deepActiveElement(this.element.ownerDocument) as HTMLElement | null);
1235+
if (handled && this.element !== activeElement && !this.element.contains(activeElement)) {
12351236
// crbug.com/1005449, crbug.com/1329956
12361237
// navigational or delete keys pressed but current DataGrid panel has lost focus;
12371238
// re-focus to ensure subsequent keydowns can be registered within this DataGrid

front_end/ui/legacy/components/data_grid/dataGrid.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@
236236
}
237237
}
238238

239-
.data-grid tbody tr.revealed:focus-within {
239+
.data-grid:focus-within tbody tr.revealed.selected {
240240
background-color: var(--sys-color-tonal-container);
241241
}
242242

0 commit comments

Comments
 (0)