Skip to content

Commit db04d08

Browse files
authored
feat(ui5-list): support pressing DELETE key (#3226)
Add DELETE shortcut key for deleting items when `mode` property is `Delete`. Also, remove the delete button from the tab chain. Related to: #3089
1 parent b90933c commit db04d08

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

packages/main/src/ListItem.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
{{#if modeDelete}}
8585
<div class="ui5-li-deletebtn">
8686
<ui5-button
87+
tabindex="-1"
8788
id="{{_id}}-deleteSelectionElement"
8889
design="Transparent"
8990
icon="decline"

packages/main/src/ListItem.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
1+
import { isSpace, isEnter, isDelete } from "@ui5/webcomponents-base/dist/Keys.js";
22
import "@ui5/webcomponents-icons/dist/decline.js";
33
import "@ui5/webcomponents-icons/dist/edit.js";
44
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
@@ -177,6 +177,10 @@ class ListItem extends ListItemBase {
177177
if (isSpace(event)) {
178178
this.fireItemPress(event);
179179
}
180+
181+
if (this.modeDelete && isDelete(event)) {
182+
this.onDelete();
183+
}
180184
}
181185

182186
_onmousedown(event) {

packages/main/test/specs/List.spec.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,19 @@ describe("List Tests", () => {
172172
assert.equal(browser.$('#lblResult').getHTML(false), "Laptop HP: 1", "itemDelete event was fired for the right item");
173173
});
174174

175+
it("mode: delete. DELETE key press - deletes item", () => {
176+
browser.url(`http://localhost:${PORT}/test-resources/pages/List_test_page.html`);
177+
list.root.setProperty("mode", "Delete");
178+
179+
const firstItem = list.getItem(0);
180+
firstItem.click();
181+
182+
assert.ok(!firstItem.getAttribute("selected"), "item is selected");
183+
184+
firstItem.keys("Delete")
185+
assert.equal(browser.$('#lblResult').getHTML(false), "Laptop HP: 1", "itemDelete event was fired for the right item");
186+
});
187+
175188
it("item size and classed, when an item has both text and description", () => {
176189
const ITEM_WITH_DESCRIPTION_AND_TITLE_HEIGHT = 80;
177190
const firstItem = $("#listWithDesc ui5-li:first-child");
@@ -355,7 +368,7 @@ describe("List Tests", () => {
355368
assert.strictEqual(item3.getProperty("focused"), true, "disabled item is skipped");
356369
});
357370

358-
it.only('should focus next interactive element if TAB is pressed when focus is on "More" growing button', () => {
371+
it('should focus next interactive element if TAB is pressed when focus is on "More" growing button', () => {
359372
const growingListButton = $('#growingListButton').shadow$("div[load-more-inner]");
360373
const nextInteractiveElement = $('#nextInteractiveElement');
361374

0 commit comments

Comments
 (0)