Skip to content

Commit

Permalink
fix(data-tables): accessibility for row enter
Browse files Browse the repository at this point in the history
rows should be focusable, and should handle enter

fix #21028
  • Loading branch information
antoniopacheco committed Jun 24, 2024
1 parent 321a085 commit 97931a3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/components/data-table/ha-data-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,11 @@ export class HaDataTable extends LitElement {
return html`
<div
aria-rowindex=${index + 2}
tabindex="0"
role="row"
.rowId=${row[this.id]}
@click=${this._handleRowClick}
@keydown=${this._handleRowKeyDown}
class="mdc-data-table__row ${classMap({
"mdc-data-table__row--selected": this._checkedRows.includes(
String(row[this.id])
Expand Down Expand Up @@ -661,6 +663,13 @@ export class HaDataTable extends LitElement {
this._checkedRowsChanged();
};

private _handleRowKeyDown = (ev: KeyboardEvent) => {
// Handle pressing enter.
if (ev.key === "Enter") {
this._handleRowClick(ev);
}
};

private _handleRowClick = (ev: Event) => {
if (
ev
Expand Down

0 comments on commit 97931a3

Please sign in to comment.