Skip to content

Commit

Permalink
fix(ui5-table-row): fire row-click on SPACE/ENTER (#2954)
Browse files Browse the repository at this point in the history
Start firing row-click upon ENTER/SPACE

FIXES: #2944
  • Loading branch information
ilhan007 committed Mar 18, 2021
1 parent 7352eb0 commit 179e05a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
7 changes: 6 additions & 1 deletion packages/main/src/TableRow.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
tabindex="{{_tabIndex}}"
@focusin="{{_onfocusin}}"
@click="{{_onrowclick}}"
@keydown="{{_onkeydown}}"
@keyup="{{_onkeyup}}"
aria-label="{{ariaLabelText}}"
data-sap-focus-ref
part="row"
Expand All @@ -21,7 +23,10 @@

{{#if shouldPopin}}
{{#each popinCells}}
<tr part="popin-row" role="row" class="{{this.classes}}" @click="{{../_onrowclick}}">
<tr part="popin-row" role="row" class="{{this.classes}}"
@click="{{../_onrowclick}}"
@keydown="{{../_onkeydown}}"
@keyup="{{../_onkeyup}}">
<td colspan="{{../visibleCellsCount}}" role="cell">
{{#if this.popinText}}
<span class="ui5-table-row-popin-title">{{this.popinText}}:</span>
Expand Down
19 changes: 19 additions & 0 deletions packages/main/src/TableRow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import { isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";

// Template
import TableRowTemplate from "./generated/templates/TableRowTemplate.lit.js";

// Styles
Expand Down Expand Up @@ -97,6 +100,22 @@ class TableRow extends UI5Element {
this.fireEvent("row-click", { row: this });
}

_onkeydown(event) {
if (isEnter(event)) {
this.fireEvent("row-click", { row: this });
}

if (isSpace(event)) {
event.preventDefault();
}
}

_onkeyup(event) {
if (isSpace(event)) {
this.fireEvent("row-click", { row: this });
}
}

_getActiveElementTagName() {
return document.activeElement.localName.toLocaleLowerCase();
}
Expand Down
12 changes: 9 additions & 3 deletions packages/main/test/specs/Table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,24 @@ describe("Table general interaction", () => {
assert.strictEqual(tableLabel.getHTML(false), "Number of poppedColumns: 4", "popinChange should be fired and columns should be 4");
});

it("tests rowClick is fired", () => {
it("tests row-click is fired", () => {
const lbl = browser.$("#testRowClickResult");
const cellInRow1 = browser.$("#testRowClickCell1");
const cellInRow2 = browser.$("#testRowClickCell2");
const row1Data = "Dublin";
const row2Data = "London";

cellInRow1.click();
assert.ok(lbl.getHTML().indexOf(row1Data), "Event rowClick fired and intercepted.");
assert.ok(lbl.getHTML().indexOf(row1Data), "Event row-click fired and intercepted.");

cellInRow2.click();
assert.ok(lbl.getHTML().indexOf(row2Data), "Event rowClick fired and intercepted.");
assert.ok(lbl.getHTML().indexOf(row2Data), "Event row-click fired and intercepted.");

cellInRow1.keys("Space");
assert.ok(lbl.getHTML().indexOf(row1Data), "Event row-click fired and intercepted.");

cellInRow2.keys("Enter");
assert.ok(lbl.getHTML().indexOf(row2Data), "Event row-click fired and intercepted.");
});

it("tests row aria-label value", () => {
Expand Down

0 comments on commit 179e05a

Please sign in to comment.