Skip to content

Commit 47d37c3

Browse files
authored
fix(ui5-upload-collection-item): make component responsive (#1579)
1 parent 1044daa commit 47d37c3

File tree

4 files changed

+84
-21
lines changed

4 files changed

+84
-21
lines changed

packages/fiori/src/UploadCollectionItem.hbs

+14-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
<div class="ui5-uci-progress-bar-remaining" style="{{styles.progressBarRemaining}}"></div>
3737
</div>
3838
<div class="ui5-uci-progress-labels">
39-
<ui5-label>{{_progressText}}</ui5-label>
39+
<ui5-label
40+
show-colon
41+
>{{_progressText}}</ui5-label>
4042
<ui5-label>{{progress}}%</ui5-label>
4143
</div>
4244
</div>
@@ -63,6 +65,17 @@
6365
@click="{{_onTerminate}}">
6466
</ui5-button>
6567
{{/if}}
68+
69+
{{#if showEditButton}}
70+
<ui5-button
71+
id="{{_id}}-editing-button"
72+
design="Transparent"
73+
icon="edit"
74+
@click="{{onDetailClick}}"
75+
class="ui5-li-detailbtn ui5-uci-edit"
76+
>
77+
</ui5-button>
78+
{{/if}}
6679
{{/if}}
6780
</div>
6881
</div>

packages/fiori/src/UploadCollectionItem.js

+43-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
22
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
3+
import ListItemType from "@ui5/webcomponents/dist/types/ListItemType.js";
34
import Button from "@ui5/webcomponents/dist/Button.js";
45
import Input from "@ui5/webcomponents/dist/Input.js";
56
import Label from "@ui5/webcomponents/dist/Label.js";
67
import Link from "@ui5/webcomponents/dist/Link.js";
78
import ListItem from "@ui5/webcomponents/dist/ListItem.js";
89
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
910
import getFileExtension from "@ui5/webcomponents-base/dist/util/getFileExtension.js";
11+
import RenderScheduler from "@ui5/webcomponents-base/dist/RenderScheduler.js";
1012
import UploadState from "./types/UploadState.js";
1113
import "@ui5/webcomponents-icons/dist/icons/refresh.js";
1214
import "@ui5/webcomponents-icons/dist/icons/stop.js";
15+
import "@ui5/webcomponents-icons/dist/icons/edit.js";
1316
import {
1417
UPLOADCOLLECTIONITEM_CANCELBUTTON_TEXT,
1518
UPLOADCOLLECTIONITEM_RENAMEBUTTON_TEXT,
@@ -254,16 +257,15 @@ class UploadCollectionItem extends ListItem {
254257
constructor() {
255258
super();
256259
this.i18nBundle = getI18nBundle("@ui5/webcomponents-fiori");
257-
}
258260

259-
onBeforeRendering() {
260-
if (!this.focused) {
261-
this._editing = false;
262-
}
261+
this._editPressed = false; // indicates if the edit btn has been pressed
263262
}
264263

264+
265265
onAfterRendering() {
266-
if (this.focused && this._editing) {
266+
if (this._editPressed) {
267+
this._editing = true;
268+
this._editPressed = false;
267269
this.focusAndSelectText();
268270
}
269271
}
@@ -273,6 +275,7 @@ class UploadCollectionItem extends ListItem {
273275

274276
const inp = this.shadowRoot.getElementById("ui5-uci-edit-input");
275277

278+
await RenderScheduler.whenDOMUpdated();
276279
if (inp.getFocusDomRef()) {
277280
inp.getFocusDomRef().setSelectionRange(0, this._fileNameWithoutExtension.length);
278281
}
@@ -286,6 +289,29 @@ class UploadCollectionItem extends ListItem {
286289
this._editing = true;
287290
}
288291

292+
/**
293+
* @override
294+
*/
295+
_onfocusout(event) {
296+
super._onfocusout(event);
297+
298+
const path = event.path || (event.composedPath && event.composedPath());
299+
300+
this._editPressed = this.isDetailPressed(event);
301+
302+
if (!this._editPressed && path.indexOf(this) > -1) {
303+
this._editing = false;
304+
}
305+
}
306+
307+
isDetailPressed(event) {
308+
const path = event.path || (event.composedPath && event.composedPath());
309+
310+
return path.some(e => {
311+
return e.classList && e.classList.contains("ui5-uci-edit");
312+
});
313+
}
314+
289315
_onInputChange(event) {
290316
if (this.shadowRoot.getElementById("ui5-uci-edit-cancel").active) {
291317
return;
@@ -398,6 +424,17 @@ class UploadCollectionItem extends ListItem {
398424
get _terminateButtonTooltip() {
399425
return this.i18nBundle.getText(UPLOADCOLLECTIONITEM_TERMINATE_BUTTON_TEXT);
400426
}
427+
428+
/**
429+
* override
430+
*/
431+
get typeDetail() {
432+
return false;
433+
}
434+
435+
get showEditButton() {
436+
return this.type === ListItemType.Detail;
437+
}
401438
}
402439

403440
UploadCollectionItem.define();

packages/fiori/src/themes/UploadCollectionItem.css

+22-9
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
.ui5-uci-content {
4949
flex: 1 1 auto;
50+
margin-right: .5rem;
5051
min-width: 0; /* fixes chrome overflow issue */
5152
}
5253

@@ -107,11 +108,30 @@ ui5-link.ui5-uci-file-name {
107108
margin-right: 0.125rem;
108109
}
109110

111+
/* Progress Box */
112+
.ui5-uci-progress-box {
113+
width: 20%;
114+
min-width: 4rem;
115+
}
116+
110117
@media(max-width: 30rem) {
111118
.ui5-uci-content-and-edit-container {
112119
display: block;
113120
}
114121

122+
.ui5-uci-content-and-progress {
123+
flex-wrap: wrap;
124+
}
125+
126+
.ui5-uci-progress-box {
127+
width: 100%;
128+
margin-top: .5rem;
129+
}
130+
131+
.ui5-uci-content {
132+
width: 100%;
133+
}
134+
115135
.ui5-uci-edit-buttons,
116136
.ui5-li-detailbtn,
117137
.ui5-li-deletebtn {
@@ -123,22 +143,15 @@ ui5-link.ui5-uci-file-name {
123143
}
124144
}
125145

126-
/* Progress Box */
127-
.ui5-uci-progress-box {
128-
width: 20%;
129-
margin-left: 0.5rem;
130-
min-width: 4rem;
131-
}
132-
133146
.ui5-uci-progress-indicator {
134147
display: flex;
135148
background: var(--sapField_Background);
136149
height: 1.125rem;
137150
min-height: 1rem;
138151
width: 100%;
139-
min-width: 4rem;
152+
min-width: 3.375rem;
140153
margin-bottom: 0.5rem;
141-
padding: 5px;
154+
padding: 5px 0;
142155
box-sizing: border-box;
143156
}
144157

packages/fiori/test/specs/UploadCollection.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,23 @@ describe("UploadCollection", () => {
9696
it("should preserve dots in the file name", () => {
9797
const latestReportsPdf = browser.$("#latestReportsPdf");
9898
const editButton = latestReportsPdf.shadow$(".ui5-li-detailbtn");
99-
99+
100100
editButton.click();
101101
browser.keys("last.reports-edited");
102102
browser.keys("Enter");
103-
103+
104104
assert.strictEqual(latestReportsPdf.getProperty("fileName"), "last.reports-edited.pdf", "file extension '.pdf' should be preserved");
105105
});
106106

107107
it("should be able to add extension, if there isn't such", () => {
108108
const noFileExtensionItem = browser.$("#noFileExtension");
109109
const editButton = noFileExtensionItem.shadow$(".ui5-li-detailbtn");
110110
const newFileName = "newFileName.newExtension";
111-
111+
112112
editButton.click();
113113
browser.keys(newFileName);
114114
browser.keys("Enter");
115-
115+
116116
assert.strictEqual(noFileExtensionItem.getProperty("fileName"), newFileName, "file name should be changed");
117117

118118
const newFileName2 = "newFileName2";
@@ -139,7 +139,7 @@ describe("UploadCollection", () => {
139139
it("should NOT show drag and drop overlay when NOT dragging files", () => {
140140
const uploadCollection = browser.$("#uploadCollection");
141141
const draggableElement = browser.$("#draggableElement");
142-
142+
143143
draggableElement.scrollIntoView();
144144
draggableElement.dragAndDrop(uploadCollection);
145145

0 commit comments

Comments
 (0)