Skip to content

Commit 8d00ab3

Browse files
Drawer: ScrollView doesn't scroll if you change the Drawer's position and openedStateMode options (T1255272) (DevExpress#28739)
1 parent 789c14c commit 8d00ab3

File tree

2 files changed

+76
-19
lines changed

2 files changed

+76
-19
lines changed

packages/devextreme/js/__internal/ui/drawer/m_drawer.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import { extend } from '@js/core/utils/extend';
1111
import { getBoundingRect } from '@js/core/utils/position';
1212
import { isDefined, isFunction } from '@js/core/utils/type';
1313
import { hasWindow } from '@js/core/utils/window';
14+
import type { PanelLocation } from '@js/ui/drawer';
1415
import Widget from '@js/ui/widget/ui.widget';
15-
16-
import { animation } from './m_drawer.animation';
17-
import OverlapStrategy from './m_drawer.rendering.strategy.overlap';
18-
import PushStrategy from './m_drawer.rendering.strategy.push';
19-
import ShrinkStrategy from './m_drawer.rendering.strategy.shrink';
16+
import { animation } from '@ts/ui/drawer/m_drawer.animation';
17+
import OverlapStrategy from '@ts/ui/drawer/m_drawer.rendering.strategy.overlap';
18+
import PushStrategy from '@ts/ui/drawer/m_drawer.rendering.strategy.push';
19+
import ShrinkStrategy from '@ts/ui/drawer/m_drawer.rendering.strategy.shrink';
2020

2121
const DRAWER_CLASS = 'dx-drawer';
2222
const DRAWER_WRAPPER_CLASS = 'dx-drawer-wrapper';
@@ -216,12 +216,13 @@ const Drawer = (Widget as any).inherit({
216216
this.$element().addClass(`${DRAWER_CLASS}-${this.option('openedStateMode')}`);
217217
},
218218

219-
_refreshPositionClass(prevPosition) {
220-
if (prevPosition) {
221-
this.$element().removeClass(`${DRAWER_CLASS}-${prevPosition}`);
222-
}
219+
_refreshPositionClass(): void {
220+
const positions = ['left', 'right', 'top', 'bottom'];
221+
const classPrefix = `${DRAWER_CLASS}-`;
223222

224-
this.$element().addClass(`${DRAWER_CLASS}-${this.calcTargetPosition()}`);
223+
this.$element()
224+
.removeClass(positions.map((position) => `${classPrefix}${position}`).join(' '))
225+
.addClass(`${classPrefix}${this.calcTargetPosition()}`);
225226
},
226227

227228
_refreshWrapperChildrenOrder() {
@@ -279,17 +280,18 @@ const Drawer = (Widget as any).inherit({
279280
this._minSize = this.option('minSize') || 0;
280281
},
281282

282-
calcTargetPosition() {
283-
const position = this.option('position');
284-
const rtl = this.option('rtlEnabled');
285-
let result = position;
283+
calcTargetPosition(): PanelLocation {
284+
const { position, rtlEnabled } = this.option();
286285

287286
if (position === 'before') {
288-
result = rtl ? 'right' : 'left';
289-
} else if (position === 'after') {
290-
result = rtl ? 'left' : 'right';
287+
return rtlEnabled ? 'right' : 'left';
291288
}
292-
return result;
289+
290+
if (position === 'after') {
291+
return rtlEnabled ? 'left' : 'right';
292+
}
293+
294+
return position;
293295
},
294296

295297
getOverlayTarget() {
@@ -511,7 +513,7 @@ const Drawer = (Widget as any).inherit({
511513
this._togglePanelContentHiddenClass();
512514
break;
513515
case 'position':
514-
this._refreshPositionClass(args.previousValue);
516+
this._refreshPositionClass();
515517
this._refreshWrapperChildrenOrder();
516518
this._invalidate();
517519
break;

packages/devextreme/testing/tests/DevExpress.ui.widgets/drawer.markup.tests.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,61 @@ QUnit.module('rendering', () => {
179179
assert.ok($element.hasClass(DRAWER_CLASS + '-top'), 'top panel position class added');
180180
});
181181

182+
[true, false].forEach((rtlEnabled) => {
183+
const panelPositions = ['top', 'bottom', 'left', 'right', 'before', 'after'];
184+
185+
const configs = [
186+
{ panelPosition: 'top', expectedClass: `${DRAWER_CLASS}-top` },
187+
{ panelPosition: 'bottom', expectedClass: `${DRAWER_CLASS}-bottom` },
188+
{ panelPosition: 'left', expectedClass: `${DRAWER_CLASS}-left` },
189+
{ panelPosition: 'right', expectedClass: `${DRAWER_CLASS}-right` },
190+
{ panelPosition: 'before', expectedClass: rtlEnabled ? `${DRAWER_CLASS}-right` : `${DRAWER_CLASS}-left` },
191+
{ panelPosition: 'after', expectedClass: rtlEnabled ? `${DRAWER_CLASS}-left` : `${DRAWER_CLASS}-right` },
192+
];
193+
194+
configs.forEach(({ panelPosition, expectedClass }) => {
195+
QUnit.test(`drawer should have ${expectedClass} class on initialization if panel position is set to ${panelPosition}, rtlEnabled=${rtlEnabled}`, function(assert) {
196+
assert.expect(6);
197+
198+
const $element = $('#contentTemplate').dxDrawer({
199+
position: panelPosition,
200+
opened: true,
201+
rtlEnabled,
202+
});
203+
204+
assert.strictEqual($element.hasClass(expectedClass), true, `class ${expectedClass} is added correctly`);
205+
206+
panelPositions
207+
.filter((position) => `${DRAWER_CLASS}-${position}` !== expectedClass)
208+
.map((position) => {
209+
assert.strictEqual($element.hasClass(`${DRAWER_CLASS}-${position}`), false, `class ${DRAWER_CLASS}-${position} is not set`);
210+
});
211+
});
212+
213+
configs.forEach(({ panelPosition: newPanelPosition, expectedClass: expectedClassAfterChange }) => {
214+
QUnit.test(`ddrawer should have ${expectedClassAfterChange} class after changing position from ${panelPosition} to ${newPanelPosition}, rtlEnabled=${rtlEnabled}`, function(assert) {
215+
const drawer = $('#contentTemplate').dxDrawer({
216+
position: panelPosition,
217+
opened: true,
218+
rtlEnabled,
219+
}).dxDrawer('instance');
220+
221+
const $element = drawer.$element();
222+
223+
drawer.option('position', newPanelPosition);
224+
225+
assert.strictEqual($element.hasClass(expectedClassAfterChange), true, `class ${expectedClassAfterChange} is added correctly`);
226+
227+
panelPositions
228+
.filter((position) => `${DRAWER_CLASS}-${position}` !== expectedClassAfterChange)
229+
.map((position) => {
230+
assert.strictEqual($element.hasClass(`${DRAWER_CLASS}-${position}`), false, `class ${DRAWER_CLASS}-${position} is not set`);
231+
});
232+
});
233+
});
234+
});
235+
});
236+
182237
QUnit.test('shader should be rendered by default if panel is visible', function(assert) {
183238
const $element = $('#drawer').dxDrawer({
184239
opened: true

0 commit comments

Comments
 (0)