Skip to content

Commit 13bdc02

Browse files
authoredMar 22, 2021
feat(framework): Maintain a common z-index for all UI5 Web Components instances and OpenUI5 (#2980)
1 parent c870eb4 commit 13bdc02

File tree

8 files changed

+64
-16
lines changed

8 files changed

+64
-16
lines changed
 

‎packages/base/hash.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
MUfM5wQo+eUhgUm/wAfVuvW4G7E=
1+
LnA57prVpk1aAMvC39RJd6Yc7Kg=

‎packages/base/src/features/OpenUI5Support.js

+41-6
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
11
import { registerFeature } from "../FeaturesRegistry.js";
22
import { setTheme } from "../config/Theme.js";
3+
import { getCurrentZIndex } from "../util/PopupUtils.js";
34

4-
const sap = window.sap;
5-
const core = sap && sap.ui && typeof sap.ui.getCore === "function" && sap.ui.getCore();
5+
const getCore = () => {
6+
const sap = window.sap;
7+
const core = sap && sap.ui && typeof sap.ui.getCore === "function" && sap.ui.getCore();
8+
return core;
9+
};
610

711
const isLoaded = () => {
8-
return !!core;
12+
return !!getCore();
913
};
1014

1115
const init = () => {
16+
const core = getCore();
1217
if (!core) {
1318
return Promise.resolve();
1419
}
1520

1621
return new Promise(resolve => {
1722
core.attachInit(() => {
18-
sap.ui.require(["sap/ui/core/LocaleData"], resolve);
23+
window.sap.ui.require(["sap/ui/core/LocaleData", "sap/ui/core/Popup"], (LocaleData, Popup) => {
24+
Popup.setInitialZIndex(getCurrentZIndex());
25+
resolve();
26+
});
1927
});
2028
});
2129
};
2230

2331
const getConfigurationSettingsObject = () => {
32+
const core = getCore();
2433
if (!core) {
2534
return;
2635
}
2736

2837
const config = core.getConfiguration();
29-
const LocaleData = sap.ui.require("sap/ui/core/LocaleData");
38+
const LocaleData = window.sap.ui.require("sap/ui/core/LocaleData");
3039

3140
return {
3241
animationMode: config.getAnimationMode(),
@@ -41,23 +50,26 @@ const getConfigurationSettingsObject = () => {
4150
};
4251

4352
const getLocaleDataObject = () => {
53+
const core = getCore();
4454
if (!core) {
4555
return;
4656
}
4757

4858
const config = core.getConfiguration();
49-
const LocaleData = sap.ui.require("sap/ui/core/LocaleData");
59+
const LocaleData = window.sap.ui.require("sap/ui/core/LocaleData");
5060
return LocaleData.getInstance(config.getLocale())._get();
5161
};
5262

5363
const listenForThemeChange = () => {
64+
const core = getCore();
5465
const config = core.getConfiguration();
5566
core.attachThemeChanged(async () => {
5667
await setTheme(config.getTheme());
5768
});
5869
};
5970

6071
const attachListeners = () => {
72+
const core = getCore();
6173
if (!core) {
6274
return;
6375
}
@@ -66,6 +78,7 @@ const attachListeners = () => {
6678
};
6779

6880
const cssVariablesLoaded = () => {
81+
const core = getCore();
6982
if (!core) {
7083
return;
7184
}
@@ -78,13 +91,35 @@ const cssVariablesLoaded = () => {
7891
return !!link.href.match(/\/css(-|_)variables\.css/);
7992
};
8093

94+
const getNextZIndex = () => {
95+
const core = getCore();
96+
if (!core) {
97+
return;
98+
}
99+
100+
const Popup = window.sap.ui.require("sap/ui/core/Popup");
101+
return Popup.getNextZIndex();
102+
};
103+
104+
const setInitialZIndex = () => {
105+
const core = getCore();
106+
if (!core) {
107+
return;
108+
}
109+
110+
const Popup = window.sap.ui.require("sap/ui/core/Popup");
111+
Popup.setInitialZIndex(getCurrentZIndex());
112+
};
113+
81114
const OpenUI5Support = {
82115
isLoaded,
83116
init,
84117
getConfigurationSettingsObject,
85118
getLocaleDataObject,
86119
attachListeners,
87120
cssVariablesLoaded,
121+
getNextZIndex,
122+
setInitialZIndex,
88123
};
89124

90125
registerFeature("OpenUI5Support", OpenUI5Support);

‎packages/main/src/popup-utils/PopupUtils.js renamed to ‎packages/base/src/util/PopupUtils.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import getActiveElement from "@ui5/webcomponents-base/dist/util/getActiveElement.js";
1+
import getSharedResource from "../getSharedResource.js";
2+
import { getFeature } from "../FeaturesRegistry.js";
3+
import getActiveElement from "./getActiveElement.js";
24

3-
let currentZIndex = 100;
5+
const PopupUtilsData = getSharedResource("PopupUtilsData", {});
6+
PopupUtilsData.currentZIndex = PopupUtilsData.currentZIndex || 100;
47

58
const getFocusedElement = () => {
69
const element = getActiveElement();
@@ -67,14 +70,24 @@ const getClosedPopupParent = el => {
6770
};
6871

6972
const getNextZIndex = () => {
70-
currentZIndex += 2;
71-
return currentZIndex;
73+
const OpenUI5Support = getFeature("OpenUI5Support");
74+
if (OpenUI5Support && OpenUI5Support.isLoaded()) { // use OpenUI5 for getting z-index values, if loaded
75+
return OpenUI5Support.getNextZIndex();
76+
}
77+
78+
PopupUtilsData.currentZIndex += 2;
79+
return PopupUtilsData.currentZIndex;
80+
};
81+
82+
const getCurrentZIndex = () => {
83+
return PopupUtilsData.currentZIndex;
7284
};
7385

7486
export {
7587
getFocusedElement,
7688
isClickInRect,
7789
getClosedPopupParent,
7890
getNextZIndex,
91+
getCurrentZIndex,
7992
isFocusedElementWithinNode,
8093
};

‎packages/main/src/Popover.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
22
import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js";
3+
import { getClosedPopupParent } from "@ui5/webcomponents-base/dist/util/PopupUtils.js";
34
import Popup from "./Popup.js";
45
import PopoverPlacementType from "./types/PopoverPlacementType.js";
56
import PopoverVerticalAlign from "./types/PopoverVerticalAlign.js";
67
import PopoverHorizontalAlign from "./types/PopoverHorizontalAlign.js";
78
import { addOpenedPopover, removeOpenedPopover } from "./popup-utils/PopoverRegistry.js";
8-
import { getClosedPopupParent } from "./popup-utils/PopupUtils.js";
99

1010
// Template
1111
import PopoverTemplate from "./generated/templates/PopoverTemplate.lit.js";

‎packages/main/src/Popup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
55
import { getFirstFocusableElement, getLastFocusableElement } from "@ui5/webcomponents-base/dist/util/FocusableElements.js";
66
import createStyleInHead from "@ui5/webcomponents-base/dist/util/createStyleInHead.js";
77
import { isTabPrevious } from "@ui5/webcomponents-base/dist/Keys.js";
8+
import { getNextZIndex, getFocusedElement, isFocusedElementWithinNode } from "@ui5/webcomponents-base/dist/util/PopupUtils.js";
89
import PopupTemplate from "./generated/templates/PopupTemplate.lit.js";
910
import PopupBlockLayer from "./generated/templates/PopupBlockLayerTemplate.lit.js";
10-
import { getNextZIndex, getFocusedElement, isFocusedElementWithinNode } from "./popup-utils/PopupUtils.js";
1111
import { addOpenedPopup, removeOpenedPopup } from "./popup-utils/OpenedPopupsRegistry.js";
1212

1313
// Styles

‎packages/main/src/ResponsivePopover.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isPhone } from "@ui5/webcomponents-base/dist/Device.js";
22
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
3+
import { getNextZIndex } from "@ui5/webcomponents-base/dist/util/PopupUtils.js";
34
import { RESPONSIVE_POPOVER_CLOSE_DIALOG_BUTTON } from "./generated/i18n/i18n-defaults.js";
4-
import { getNextZIndex } from "./popup-utils/PopupUtils.js";
55
import ResponsivePopoverTemplate from "./generated/templates/ResponsivePopoverTemplate.lit.js";
66
import Popover from "./Popover.js";
77
import Dialog from "./Dialog.js";

‎packages/main/src/Toast.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
22
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
33
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
4+
import { getNextZIndex } from "@ui5/webcomponents-base/dist/util/PopupUtils.js";
45
import ToastPlacement from "./types/ToastPlacement.js";
5-
import { getNextZIndex } from "./popup-utils/PopupUtils.js";
66

77
// Template
88
import ToastTemplate from "./generated/templates/ToastTemplate.lit.js";

‎packages/main/src/popup-utils/PopoverRegistry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isClickInRect } from "./PopupUtils.js";
1+
import { isClickInRect } from "@ui5/webcomponents-base/dist/util/PopupUtils.js";
22
import { getOpenedPopups, addOpenedPopup, removeOpenedPopup } from "./OpenedPopupsRegistry.js";
33

44
let updateInterval = null;

0 commit comments

Comments
 (0)
Please sign in to comment.