Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui5-upload-collection-item): delete can be triggered by keyboard now #9678

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/fiori/src/UploadCollectionItem.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@
{{#if renderUploadCollectionDeleteButton}}
<ui5-button
class="ui5-upload-collection-deletebtn"
tabindex="-1"
data-sap-no-tab-ref
id="{{_id}}-deleteSelectionElement"
design="Transparent"
icon="decline"
Expand Down
15 changes: 14 additions & 1 deletion packages/fiori/src/UploadCollectionItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import ProgressIndicator from "@ui5/webcomponents/dist/ProgressIndicator.js";
import ListItem from "@ui5/webcomponents/dist/ListItem.js";
import getFileExtension from "@ui5/webcomponents-base/dist/util/getFileExtension.js";
import { renderFinished } from "@ui5/webcomponents-base/dist/Render.js";
import { isEnter, isEscape, isSpace } from "@ui5/webcomponents-base/dist/Keys.js";
import {
isDelete,
isEnter,
isEscape,
isSpace,
} from "@ui5/webcomponents-base/dist/Keys.js";
import UploadState from "./types/UploadState.js";
import "@ui5/webcomponents-icons/dist/refresh.js";
import "@ui5/webcomponents-icons/dist/stop.js";
Expand Down Expand Up @@ -241,6 +246,14 @@ class UploadCollectionItem extends ListItem implements IUploadCollectionItem {
}
}

_onkeyup(e: KeyboardEvent) {
super._onkeyup(e);

if (isDelete(e) && !this.disableDeleteButton && !this.hideDeleteButton && !this.disabled) {
this._onDelete();
}
}

_onDetailKeyup(e: KeyboardEvent) {
if (isSpace(e)) {
this.onDetailClick();
Expand Down
1 change: 0 additions & 1 deletion packages/fiori/src/themes/UploadCollectionItem.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

.ui5-uci-buttons {
display: flex;
pointer-events: all;
margin-inline-start: 1rem;
gap: 0.5rem;
}
Expand Down
17 changes: 17 additions & 0 deletions packages/fiori/test/pages/UploadCollection.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@
<ui5-icon name="document-text" slot="thumbnail"></ui5-icon>
Some description.
</ui5-upload-collection-item>
<ui5-upload-collection-item
id="reportPdf"
file-name="report.pdf"
upload-state="Complete"
>
<ui5-icon name="document-text" slot="thumbnail"></ui5-icon>
Some description.
</ui5-upload-collection-item>
<ui5-upload-collection-item
id="disabledPdf"
file-name="disabledFile.pdf"
upload-state="Complete"
disabled
>
<ui5-icon name="document-text" slot="thumbnail"></ui5-icon>
Some description.
</ui5-upload-collection-item>
<ui5-upload-collection-item
id="noFileExtension"
file-name="noextension"
Expand Down
57 changes: 45 additions & 12 deletions packages/fiori/test/specs/UploadCollection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ describe("UploadCollection", () => {
await browser.keys("Enter")
});

it("Disabled item", async () => {
const item = await browser.$("#disabledPdf");
const deleteBtn = await item.shadow$(".ui5-upload-collection-deletebtn");

assert.notOk(await item.isClickable(), "Item shouldn't be clickable");
assert.notOk(await deleteBtn.isClickable(), "Delete button shouldn't be clickable");
});

});

describe("Events", () => {
Expand Down Expand Up @@ -160,28 +168,28 @@ describe("UploadCollection", () => {
await browser.keys("Enter")
});

it("upload collection should fire 'item-delete' in Delete mode", async () => {
it("upload collection should fire 'item-delete' regardless of the mode", async () => {
const uploadCollection = await browser.$("#uploadCollection");
const firstItem = await browser.$("#firstItem");
const item = await browser.$("#latestReportsPdf");
const itemsLength = (await uploadCollection.getProperty("items")).length;

await uploadCollection.setAttribute("mode", "Delete");
await uploadCollection.setAttribute("mode", "None");

const deleteBtn = await firstItem.shadow$(".ui5-upload-collection-deletebtn");
const deleteBtn = await item.shadow$(".ui5-upload-collection-deletebtn");
await deleteBtn.click();

assert.strictEqual((await uploadCollection.getProperty("items")).length, 4, "item should be deleted when 'item-delete' event is fired");
assert.strictEqual((await uploadCollection.getProperty("items")).length, itemsLength - 1, "item should be deleted when 'item-delete' event is fired");
});

it("upload collection should fire 'item-delete' regardless of the mode", async () => {
it("upload collection should fire 'item-delete' when 'DELETE' key is pressed on item", async () => {
const uploadCollection = await browser.$("#uploadCollection");
const item = await browser.$("#latestReportsPdf");

await uploadCollection.setAttribute("mode", "None");
const item = await browser.$("#reportPdf");
const itemsLength = (await uploadCollection.getProperty("items")).length;

const deleteBtn = await item.shadow$(".ui5-upload-collection-deletebtn");
await deleteBtn.click();
await item.click();
await browser.keys("Delete");

assert.strictEqual((await uploadCollection.getProperty("items")).length, 3, "item should be deleted when 'item-delete' event is fired");
assert.strictEqual((await uploadCollection.getProperty("items")).length, itemsLength - 1, "item should be deleted when 'item-delete' event is fired");
});

it("item should fire 'retry'", async () => {
Expand All @@ -203,6 +211,31 @@ describe("UploadCollection", () => {
});
});

describe("Keyboard handling", () => {
it("Tab chain", async () => {
const isActiveElement = (element) => {
return browser.executeAsync((expectedActiveElem, done) => {
const activeElement = document.activeElement;
done(activeElement.shadowRoot.activeElement === expectedActiveElem);
}, element);
};

const item = await browser.$("#hiddenFileName");

await item.click();
assert.ok(await item.isFocused(), "Item should be focused");

await browser.keys("Tab");
assert.ok(await isActiveElement(await item.shadow$("[ui5-button][icon=refresh]")), "Retry button should be focused");

await browser.keys("Tab");
assert.ok(await isActiveElement(await item.shadow$(".ui5-uci-edit")), "Edit button should be focused");

await browser.keys("Tab");
assert.ok(await isActiveElement(await item.shadow$(".ui5-upload-collection-deletebtn")), "Delete button should be focused");
});
});

describe("Edit - various file names", async () => {
before(async () => {
await browser.url(`test/pages/UploadCollection.html`);
Expand Down