Skip to content

Commit cb474fe

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

File tree

4 files changed

+95
-10
lines changed

4 files changed

+95
-10
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/m_overlay.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ interface OverlayProperties extends Properties {
9090

9191
restorePosition?: boolean;
9292

93+
zIndex?: number;
94+
9395
_fixWrapperPosition?: boolean;
9496

9597
_skipContentPositioning?: boolean;
@@ -722,24 +724,42 @@ class Overlay<
722724
this._toggleSubscriptions(visible);
723725
}
724726

727+
_handleZIndexOptionChanged(): void {
728+
const { zIndex } = this.option();
729+
730+
this._zIndex = zIndex ?? zIndexPool.create(this._zIndexInitValue());
731+
732+
this._updateZIndexStackPosition(this._isVisible());
733+
}
734+
725735
_updateZIndexStackPosition(pushToStack: boolean): void {
726736
const overlayStack = this._overlayStack();
727737
// @ts-expect-error ts-error
728738
const index = overlayStack.indexOf(this);
739+
const isInStack = index !== -1;
740+
const { zIndex } = this.option();
729741

730-
if (pushToStack) {
731-
if (index === -1) {
732-
this._zIndex = zIndexPool.create(this._zIndexInitValue());
733-
// @ts-expect-error ts-error
734-
overlayStack.push(this);
742+
if (!pushToStack) {
743+
if (isInStack) {
744+
overlayStack.splice(index, 1);
745+
zIndexPool.remove(this._zIndex);
735746
}
736747

737-
this._$wrapper.css('zIndex', this._zIndex);
738-
this._$content.css('zIndex', this._zIndex);
739-
} else if (index !== -1) {
740-
overlayStack.splice(index, 1);
741-
zIndexPool.remove(this._zIndex);
748+
return;
742749
}
750+
751+
if (!isInStack) {
752+
this._zIndex = zIndex ?? zIndexPool.create(this._zIndexInitValue());
753+
// @ts-expect-error this and Overlay have no overlap
754+
overlayStack.push(this);
755+
}
756+
757+
this._updateZIndex();
758+
}
759+
760+
_updateZIndex(): void {
761+
this._$wrapper.css('zIndex', this._zIndex);
762+
this._$content.css('zIndex', this._zIndex);
743763
}
744764

745765
_toggleShading(visible?: boolean): void {
@@ -1319,6 +1339,9 @@ class Overlay<
13191339
this._initHideTopOverlayHandler(value);
13201340
this._toggleHideTopOverlayCallback(this.option('visible'));
13211341
break;
1342+
case 'zIndex':
1343+
this._handleZIndexOptionChanged();
1344+
break;
13221345
case 'hideOnParentScroll':
13231346
case '_hideOnParentScrollTarget': {
13241347
const { visible } = this.option();

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
@@ -1275,6 +1275,21 @@ QUnit.module('Initialization', baseModuleConfig, () => {
12751275
// assert
12761276
assert.strictEqual(onContentReadySpy.callCount, 1, 'onContentReadySpy call count');
12771277
});
1278+
1279+
QUnit.test('Load panel has custom z-index (T1308742)', function(assert) {
1280+
const dataGrid = createDataGrid({
1281+
dataSource: {
1282+
load: function() {
1283+
return;
1284+
}
1285+
}
1286+
});
1287+
1288+
const loadPanel = dataGrid.getView('rowsView')._loadPanel;
1289+
const loadPanelZIndex = loadPanel._zIndex;
1290+
1291+
assert.strictEqual(loadPanelZIndex, 1000, 'load z-index is set to 1000 by default');
1292+
});
12781293
});
12791294

12801295

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3108,6 +3108,50 @@ testModule('API', moduleConfig, () => {
31083108
assert.strictEqual(resizeStub.callCount, 1, '\'dxresize\' event handler was called');
31093109
resizeStub.restore();
31103110
});
3111+
3112+
test('Overlay uses custom zIndex on init if zIndex option is provided', function(assert) {
3113+
const overlay = $('#overlay').dxOverlay({
3114+
visible: true,
3115+
zIndex: 2000
3116+
}).dxOverlay('instance');
3117+
3118+
const contentZIndex = Number(getComputedStyle(overlay.$content()[0]).zIndex);
3119+
3120+
assert.strictEqual(contentZIndex, 2000, 'custom zIndex assigned');
3121+
});
3122+
3123+
test('Changing zIndex option replaces old pool zIndex with custom', function(assert) {
3124+
const overlay = $('#overlay').dxOverlay({
3125+
visible: true
3126+
}).dxOverlay('instance');
3127+
3128+
const initialZIndex = Number(getComputedStyle(overlay.$content()[0]).zIndex);
3129+
3130+
assert.strictEqual(initialZIndex, 1501, 'overlay has initial pool zIndex');
3131+
3132+
overlay.option('zIndex', 5000);
3133+
3134+
const finalZIndex = Number(getComputedStyle(overlay.$content()[0]).zIndex);
3135+
3136+
assert.strictEqual(finalZIndex, 5000, 'custom zIndex applied');
3137+
});
3138+
3139+
test('Changing zIndex option to undefined resets the default pool zIndex', function(assert) {
3140+
const overlay = $('#overlay').dxOverlay({
3141+
visible: true,
3142+
zIndex: 5000
3143+
}).dxOverlay('instance');
3144+
3145+
const initialZIndex = Number(getComputedStyle(overlay.$content()[0]).zIndex);
3146+
3147+
assert.strictEqual(initialZIndex, 5000, 'overlay has custom zIndex');
3148+
3149+
overlay.option('zIndex', undefined);
3150+
3151+
const finalZIndex = Number(getComputedStyle(overlay.$content()[0]).zIndex);
3152+
3153+
assert.strictEqual(finalZIndex, 1501, 'initial pool zIndex applied');
3154+
});
31113155
});
31123156

31133157

0 commit comments

Comments
 (0)