Skip to content

Commit 1e328dc

Browse files
authoredMar 17, 2021
fix(ui5-table-row): fire row-click on SPACE/ENTER (#2954)
Start firing row-click upon ENTER/SPACE FIXES: #2944
1 parent c117fe3 commit 1e328dc

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed
 

‎packages/main/src/TableRow.hbs

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
tabindex="{{_tabIndex}}"
44
@focusin="{{_onfocusin}}"
55
@click="{{_onrowclick}}"
6+
@keydown="{{_onkeydown}}"
7+
@keyup="{{_onkeyup}}"
68
aria-label="{{ariaLabelText}}"
79
data-sap-focus-ref
810
part="row"
@@ -21,7 +23,10 @@
2123

2224
{{#if shouldPopin}}
2325
{{#each popinCells}}
24-
<tr part="popin-row" role="row" class="{{this.classes}}" @click="{{../_onrowclick}}">
26+
<tr part="popin-row" role="row" class="{{this.classes}}"
27+
@click="{{../_onrowclick}}"
28+
@keydown="{{../_onkeydown}}"
29+
@keyup="{{../_onkeyup}}">
2530
<td colspan="{{../visibleCellsCount}}" role="cell">
2631
{{#if this.popinText}}
2732
<span class="ui5-table-row-popin-title">{{this.popinText}}:</span>

‎packages/main/src/TableRow.js

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
22
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
3+
import { isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
4+
5+
// Template
36
import TableRowTemplate from "./generated/templates/TableRowTemplate.lit.js";
47

58
// Styles
@@ -98,6 +101,22 @@ class TableRow extends UI5Element {
98101
this.fireEvent("row-click", { row: this });
99102
}
100103

104+
_onkeydown(event) {
105+
if (isEnter(event)) {
106+
this.fireEvent("row-click", { row: this });
107+
}
108+
109+
if (isSpace(event)) {
110+
event.preventDefault();
111+
}
112+
}
113+
114+
_onkeyup(event) {
115+
if (isSpace(event)) {
116+
this.fireEvent("row-click", { row: this });
117+
}
118+
}
119+
101120
_getActiveElementTagName() {
102121
return document.activeElement.localName.toLocaleLowerCase();
103122
}

‎packages/main/test/specs/Table.spec.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,24 @@ describe("Table general interaction", () => {
4545
assert.strictEqual(tableLabel.getHTML(false), "Number of poppedColumns: 4", "popinChange should be fired and columns should be 4");
4646
});
4747

48-
it("tests rowClick is fired", () => {
48+
it("tests row-click is fired", () => {
4949
const lbl = browser.$("#testRowClickResult");
5050
const cellInRow1 = browser.$("#testRowClickCell1");
5151
const cellInRow2 = browser.$("#testRowClickCell2");
5252
const row1Data = "Dublin";
5353
const row2Data = "London";
5454

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

5858
cellInRow2.click();
59-
assert.ok(lbl.getHTML().indexOf(row2Data), "Event rowClick fired and intercepted.");
59+
assert.ok(lbl.getHTML().indexOf(row2Data), "Event row-click fired and intercepted.");
60+
61+
cellInRow1.keys("Space");
62+
assert.ok(lbl.getHTML().indexOf(row1Data), "Event row-click fired and intercepted.");
63+
64+
cellInRow2.keys("Enter");
65+
assert.ok(lbl.getHTML().indexOf(row2Data), "Event row-click fired and intercepted.");
6066
});
6167

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

0 commit comments

Comments
 (0)
Please sign in to comment.