Skip to content

Commit 1008882

Browse files
r-farkhutdinovRuslan Farkhutdinov
andauthored
Overlay: Add zIndex option & specify it for LoadPanel in Grid (T1308742) (DevExpress#31815)
Co-authored-by: Ruslan Farkhutdinov <[email protected]>
1 parent bae0c42 commit 1008882

File tree

4 files changed

+95
-11
lines changed

4 files changed

+95
-11
lines changed

packages/devextreme/js/__internal/grids/grid_core/m_utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import type { ColumnPoint } from '@ts/grids/grid_core/m_types';
2323

2424
import { isEqualSelectors, isSelectorEqualWithCallback } from './utils/index';
2525

26+
const BASE_LOAD_PANEL_Z_INDEX = 1000;
27+
2628
const DATAGRID_SELECTION_DISABLED_CLASS = 'dx-selection-disabled';
2729
const DATAGRID_GROUP_OPENED_CLASS = 'dx-datagrid-group-opened';
2830
const DATAGRID_GROUP_CLOSED_CLASS = 'dx-datagrid-group-closed';
@@ -230,6 +232,7 @@ export default {
230232
shading: false,
231233
message: loadPanelOptions.text,
232234
container: $container,
235+
zIndex: BASE_LOAD_PANEL_Z_INDEX,
233236
}, loadPanelOptions);
234237

235238
that._loadPanel = that._createComponent($('<div>').appendTo($container), LoadPanel, loadPanelOptions);

packages/devextreme/js/__internal/ui/overlay/overlay.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ export interface OverlayProperties extends Properties {
118118

119119
templatesRenderAsynchronously?: boolean;
120120

121+
zIndex?: number;
122+
121123
_loopFocus?: boolean;
122124

123125
_ignorePreventScrollEventsDeprecation?: boolean;
@@ -877,25 +879,42 @@ class Overlay<
877879
this._toggleSubscriptions(visible);
878880
}
879881

882+
_handleZIndexOptionChanged(): void {
883+
const { zIndex } = this.option();
884+
885+
this._zIndex = zIndex ?? zIndexPool.create(this._zIndexInitValue());
886+
887+
this._updateZIndexStackPosition(this._isVisible());
888+
}
889+
880890
_updateZIndexStackPosition(pushToStack: boolean): void {
881891
const overlayStack = this._overlayStack();
882892
// @ts-expect-error this and Overlay have no overlap
883893
const index = overlayStack.indexOf(this);
894+
const isInStack = index !== -1;
895+
const { zIndex } = this.option();
884896

885-
if (pushToStack) {
886-
if (index === -1) {
887-
this._zIndex = zIndexPool.create(this._zIndexInitValue());
888-
889-
// @ts-expect-error this and Overlay have no overlap
890-
overlayStack.push(this);
897+
if (!pushToStack) {
898+
if (isInStack) {
899+
overlayStack.splice(index, 1);
900+
zIndexPool.remove(this._zIndex);
891901
}
892902

893-
this._$wrapper.css('zIndex', this._zIndex);
894-
this._$content.css('zIndex', this._zIndex);
895-
} else if (index !== -1) {
896-
overlayStack.splice(index, 1);
897-
zIndexPool.remove(this._zIndex);
903+
return;
904+
}
905+
906+
if (!isInStack) {
907+
this._zIndex = zIndex ?? zIndexPool.create(this._zIndexInitValue());
908+
// @ts-expect-error this and Overlay have no overlap
909+
overlayStack.push(this);
898910
}
911+
912+
this._updateZIndex();
913+
}
914+
915+
_updateZIndex(): void {
916+
this._$wrapper.css('zIndex', this._zIndex);
917+
this._$content.css('zIndex', this._zIndex);
899918
}
900919

901920
_toggleShading(visible?: boolean): void {
@@ -1551,6 +1570,9 @@ class Overlay<
15511570
this._initHideTopOverlayHandler(value);
15521571
this._toggleHideTopOverlayCallback(this._isVisible());
15531572
break;
1573+
case 'zIndex':
1574+
this._handleZIndexOptionChanged();
1575+
break;
15541576
case 'hideOnParentScroll':
15551577
case '_hideOnParentScrollTarget': {
15561578
this._toggleHideOnParentsScrollSubscription(this._isVisible());

packages/devextreme/testing/tests/DevExpress.ui.widgets.dataGrid/dataGrid.tests.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,21 @@ QUnit.module('Initialization', baseModuleConfig, () => {
12601260
// assert
12611261
assert.strictEqual(onContentReadySpy.callCount, 1, 'onContentReadySpy call count');
12621262
});
1263+
1264+
QUnit.test('Load panel has custom z-index (T1308742)', function(assert) {
1265+
const dataGrid = createDataGrid({
1266+
dataSource: {
1267+
load: function() {
1268+
return;
1269+
}
1270+
}
1271+
});
1272+
1273+
const loadPanel = dataGrid.getView('rowsView')._loadPanel;
1274+
const loadPanelZIndex = loadPanel._zIndex;
1275+
1276+
assert.strictEqual(loadPanelZIndex, 1000, 'load z-index is set to 1000 by default');
1277+
});
12631278
});
12641279

12651280

packages/devextreme/testing/tests/DevExpress.ui.widgets/overlay.tests.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3073,6 +3073,50 @@ testModule('API', moduleConfig, () => {
30733073
assert.strictEqual(resizeStub.callCount, 1, '\'dxresize\' event handler was called');
30743074
resizeStub.restore();
30753075
});
3076+
3077+
test('Overlay uses custom zIndex on init if zIndex option is provided', function(assert) {
3078+
const overlay = $('#overlay').dxOverlay({
3079+
visible: true,
3080+
zIndex: 2000
3081+
}).dxOverlay('instance');
3082+
3083+
const contentZIndex = Number(getComputedStyle(overlay.$content()[0]).zIndex);
3084+
3085+
assert.strictEqual(contentZIndex, 2000, 'custom zIndex assigned');
3086+
});
3087+
3088+
test('Changing zIndex option replaces old pool zIndex with custom', function(assert) {
3089+
const overlay = $('#overlay').dxOverlay({
3090+
visible: true
3091+
}).dxOverlay('instance');
3092+
3093+
const initialZIndex = Number(getComputedStyle(overlay.$content()[0]).zIndex);
3094+
3095+
assert.strictEqual(initialZIndex, 1501, 'overlay has initial pool zIndex');
3096+
3097+
overlay.option('zIndex', 5000);
3098+
3099+
const finalZIndex = Number(getComputedStyle(overlay.$content()[0]).zIndex);
3100+
3101+
assert.strictEqual(finalZIndex, 5000, 'custom zIndex applied');
3102+
});
3103+
3104+
test('Changing zIndex option to undefined resets the default pool zIndex', function(assert) {
3105+
const overlay = $('#overlay').dxOverlay({
3106+
visible: true,
3107+
zIndex: 5000
3108+
}).dxOverlay('instance');
3109+
3110+
const initialZIndex = Number(getComputedStyle(overlay.$content()[0]).zIndex);
3111+
3112+
assert.strictEqual(initialZIndex, 5000, 'overlay has custom zIndex');
3113+
3114+
overlay.option('zIndex', undefined);
3115+
3116+
const finalZIndex = Number(getComputedStyle(overlay.$content()[0]).zIndex);
3117+
3118+
assert.strictEqual(finalZIndex, 1501, 'initial pool zIndex applied');
3119+
});
30763120
});
30773121

30783122

0 commit comments

Comments
 (0)