Skip to content

Commit a5d3dd7

Browse files
authored
refactor(ui5-popup): Move more common functionality to Popup.js (#1853)
1 parent 4027bb8 commit a5d3dd7

15 files changed

+354
-327
lines changed

packages/main/bundle.esm.js

-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ import StandardListItem from "./dist/StandardListItem.js";
7878
import CustomListItem from "./dist/CustomListItem.js";
7979
import GroupHeaderListItem from "./dist/GroupHeaderListItem.js";
8080

81-
82-
8381
// used in test pages
8482
import RenderScheduler from "@ui5/webcomponents-base/dist/RenderScheduler.js";
8583
window.RenderScheduler = RenderScheduler;

packages/main/src/Dialog.hbs

+20-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1-
{{>include "./Popup.hbs"}}
1+
{{>include "./Popup.hbs"}}
2+
3+
{{#*inline "beforeContent"}}
4+
<header class="ui5-popup-header-root" id="ui5-popup-header">
5+
{{#if header.length }}
6+
<slot name="header"></slot>
7+
{{else}}
8+
<h2 class="ui5-popup-header-text">{{headerText}}</h2>
9+
{{/if}}
10+
</header>
11+
{{/inline}}
12+
13+
{{#*inline "afterContent"}}
14+
{{#if footer.length }}
15+
<footer class="ui5-popup-footer-root">
16+
<slot name="footer"></slot>
17+
</footer>
18+
{{/if}}
19+
{{/inline}}
20+

packages/main/src/Dialog.js

+56-62
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,54 @@
11
import { isPhone } from "@ui5/webcomponents-base/dist/Device.js";
2-
import { addOpenedPopup, removeOpenedPopup } from "./popup-utils/OpenedPopupsRegistry.js";
3-
42
import Popup from "./Popup.js";
3+
54
// Template
65
import DialogTemplate from "./generated/templates/DialogTemplate.lit.js";
7-
86
// Styles
7+
import PopupsCommonCss from "./generated/themes/PopupsCommon.css.js";
98
import dialogCSS from "./generated/themes/Dialog.css.js";
10-
import { getFocusedElement } from "./popup-utils/PopupUtils.js";
119

1210
/**
1311
* @public
1412
*/
1513
const metadata = {
1614
tag: "ui5-dialog",
15+
slots: /** @lends sap.ui.webcomponents.main.Popup.prototype */ {
16+
/**
17+
* Defines the header HTML Element.
18+
*
19+
* @type {HTMLElement[]}
20+
* @slot
21+
* @public
22+
*/
23+
header: {
24+
type: HTMLElement,
25+
},
26+
27+
/**
28+
* Defines the footer HTML Element.
29+
*
30+
* @type {HTMLElement[]}
31+
* @slot
32+
* @public
33+
*/
34+
footer: {
35+
type: HTMLElement,
36+
},
37+
},
1738
properties: /** @lends sap.ui.webcomponents.main.Dialog.prototype */ {
39+
/**
40+
* Defines the header text.
41+
* <br><br>
42+
* <b>Note:</b> If <code>header</code> slot is provided, the <code>headerText</code> is ignored.
43+
*
44+
* @type {string}
45+
* @defaultvalue ""
46+
* @public
47+
*/
48+
headerText: {
49+
type: String,
50+
},
51+
1852
/**
1953
* Determines whether the <code>ui5-dialog</code> should be stretched to fullscreen.
2054
* <br><br>
@@ -29,6 +63,9 @@ const metadata = {
2963
type: Boolean,
3064
},
3165

66+
/**
67+
* @private
68+
*/
3269
onPhone: {
3370
type: Boolean,
3471
},
@@ -78,77 +115,34 @@ class Dialog extends Popup {
78115
}
79116

80117
static get styles() {
81-
return [Popup.styles, dialogCSS];
82-
}
83-
84-
constructor() {
85-
super();
118+
return [PopupsCommonCss, dialogCSS];
86119
}
87120

88121
onBeforeRendering() {
89122
this.onPhone = isPhone();
90123
}
91124

92-
/**
93-
* Opens the <code>ui5-dialog</code>.
94-
* @public
95-
*/
96-
open() {
97-
super.open();
98-
99-
this._focusedElementBeforeOpen = getFocusedElement();
100-
this.fireEvent("before-open", {});
101-
this.show();
102-
this.applyInitialFocus();
103-
104-
Dialog.blockBodyScrolling();
105-
106-
addOpenedPopup(this);
107-
this.opened = true;
108-
this.fireEvent("after-open", {});
109-
}
110-
111-
/**
112-
* Closes the <code>ui5-dialog</code>.
113-
* @public
114-
*/
115-
close(escPressed) {
116-
const prevented = !this.fireEvent("before-close", { escPressed }, true);
117-
118-
if (prevented || !this.opened) {
119-
return;
120-
}
121-
122-
super.close();
123-
this.hide();
124-
this.opened = false;
125-
126-
this.fireEvent("after-close", {});
127-
128-
removeOpenedPopup(this);
129-
Dialog.unblockBodyScrolling();
130-
131-
if (this._focusedElementBeforeOpen && !this._disableInitialFocus) {
132-
this._focusedElementBeforeOpen.focus();
133-
}
125+
get isModal() { // Required by Popup.js
126+
return true;
134127
}
135128

136-
onExitDOM() {
137-
if (this.isOpen()) {
138-
Dialog.unblockBodyScrolling();
139-
}
129+
get _ariaLabelledBy() { // Required by Popup.js
130+
return "ui5-popup-header";
140131
}
141132

142-
get isModal() {
133+
get _ariaModal() { // Required by Popup.js
143134
return true;
144135
}
145136

146-
get _displayFooter() {
147-
return true;
148-
}
149-
150-
get _displayHeader() {
151-
return true;
137+
get classes() {
138+
return {
139+
root: {
140+
"ui5-popup-root": true,
141+
},
142+
content: {
143+
"ui5-popup-content": true,
144+
},
145+
};
152146
}
153147
}
154148

packages/main/src/Popover.hbs

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
{{>include "./Popup.hbs"}}
22

3-
{{#*inline "beforeHeader"}}
3+
{{#*inline "beforeContent"}}
44
<span class="ui5-popover-arrow" style="{{styles.arrow}}"></span>
5-
{{/inline}}
5+
6+
{{#if _displayHeader}}
7+
<header class="ui5-popup-header-root" id="ui5-popup-header">
8+
{{#if header.length }}
9+
<slot name="header"></slot>
10+
{{else}}
11+
<h2 class="ui5-popup-header-text">{{headerText}}</h2>
12+
{{/if}}
13+
</header>
14+
{{/if}}
15+
{{/inline}}
16+
17+
{{#*inline "afterContent"}}
18+
{{#if _displayFooter}}
19+
{{#if footer.length }}
20+
<footer class="ui5-popup-footer-root">
21+
<slot name="footer"></slot>
22+
</footer>
23+
{{/if}}
24+
{{/if}}
25+
{{/inline}}

0 commit comments

Comments
 (0)