Skip to content

Commit 3c6f2f4

Browse files
authored
Drawer: hide animation should work on hide using opened option (T1277636) + Promise should be resolved after call show() for already opened drawer (T1263952)
1 parent 4a3123b commit 3c6f2f4

File tree

2 files changed

+116
-27
lines changed

2 files changed

+116
-27
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,17 @@ const Drawer = (Widget as any).inherit({
391391

392392
_renderPosition(isDrawerOpened, disableAnimation, jumpToEnd) {
393393
this.stopAnimations(jumpToEnd);
394+
this._whenAnimationCompleted = Deferred();
395+
396+
let { animationEnabled } = this.option();
397+
398+
if (disableAnimation === true) {
399+
animationEnabled = false;
400+
}
401+
402+
if (!animationEnabled) {
403+
this._whenAnimationCompleted.resolve();
404+
}
394405

395406
if (!hasWindow()) {
396407
return;
@@ -402,11 +413,6 @@ const Drawer = (Widget as any).inherit({
402413
$(this.viewContent()).css('paddingTop', 0);
403414
$(this.viewContent()).css('paddingBottom', 0);
404415

405-
let animationEnabled = this.option('animationEnabled');
406-
if (disableAnimation === true) {
407-
animationEnabled = false;
408-
}
409-
410416
if (isDrawerOpened) {
411417
this._toggleShaderVisibility(isDrawerOpened);
412418
}
@@ -417,9 +423,7 @@ const Drawer = (Widget as any).inherit({
417423
_animationCompleteHandler() {
418424
this.resizeViewContent();
419425

420-
if (this._whenAnimationCompleted) {
421-
this._whenAnimationCompleted.resolve();
422-
}
426+
this._whenAnimationCompleted.resolve();
423427
},
424428

425429
_getPositionCorrection() {
@@ -572,7 +576,6 @@ const Drawer = (Widget as any).inherit({
572576
toggle(opened) {
573577
const targetOpened = opened === undefined ? !this.option('opened') : opened;
574578

575-
this._whenAnimationCompleted = Deferred();
576579
this.option('opened', targetOpened);
577580

578581
return this._whenAnimationCompleted.promise();

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

Lines changed: 104 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -143,39 +143,125 @@ QUnit.module('Drawer behavior', () => {
143143
assert.equal($element.attr('tabIndex'), undefined, 'tabIndex was removed');
144144
});
145145

146-
QUnit.test('subscribe on toggle function should fired at the end of animation', function(assert) {
147-
const $element = $('#drawer').dxDrawer({
148-
opened: false
146+
[true, false].forEach((animationEnabled) => {
147+
QUnit.test(`Toggle promise should be resolved after toggle finished (animationEnabled=${animationEnabled})`, function(assert) {
148+
assert.expect(1);
149+
150+
const instance = $('#drawer').dxDrawer({
151+
animationEnabled,
152+
animationDuration: 0,
153+
}).dxDrawer('instance');
154+
155+
const done = assert.async();
156+
157+
const timeout = setTimeout(() => {
158+
assert.ok(false, 'toggle promise was not resolved');
159+
done();
160+
}, 10);
161+
162+
instance.toggle().then(() => {
163+
clearTimeout(timeout);
164+
assert.ok(true, 'toggle promise was resolved');
165+
done();
166+
});
167+
});
168+
});
169+
170+
[
171+
{
172+
opened: true,
173+
scenario: 'show method call if drawer is already opened',
174+
},
175+
{
176+
opened: false,
177+
scenario: 'hide method call if drawer is already closed',
178+
},
179+
].forEach(({ opened, scenario }) => {
180+
QUnit.test(`Promise should be resolved after ${scenario} (T1263952)`, function(assert) {
181+
assert.expect(1);
182+
183+
const instance = $('#drawer').dxDrawer({
184+
opened
185+
}).dxDrawer('instance');
186+
187+
const done = assert.async();
188+
189+
const timeout = setTimeout(() => {
190+
assert.ok(false, 'promise was not resolved');
191+
done();
192+
}, 10);
193+
194+
const methodToCall = opened ? 'show' : 'hide';
195+
196+
instance[methodToCall]().then(() => {
197+
clearTimeout(timeout);
198+
assert.ok(true, 'promise was resolved');
199+
done();
200+
});
149201
});
202+
});
150203

204+
QUnit.test('Drawer panel should add a hidden class after hide animation is completed, toggle method is used (T1239845)', function(assert) {
205+
const $element = $('#drawer').dxDrawer({ animationDuration: 0, opened: true });
151206
const instance = $element.dxDrawer('instance');
152-
let count = 0;
207+
const $panel = $element.find(`.${DRAWER_PANEL_CONTENT_CLASS}`);
208+
153209
const done = assert.async();
154210

155211
instance.toggle().then(() => {
156-
count++;
157-
assert.equal(count, 1, 'callback not fired at animation start');
212+
assert.strictEqual($panel.hasClass(DRAWER_PANEL_CONTENT_HIDDEN_CLASS), true, 'dx-drawer-panel-content-hidden is set after animation completed');
158213
done();
159214
});
160215

161-
assert.equal(count, 0, 'callback not fired at animation start');
216+
assert.strictEqual($panel.hasClass(DRAWER_PANEL_CONTENT_HIDDEN_CLASS), false, 'dx-drawer-panel-content-hidden is not set before animation start');
162217
});
163218

164-
[true, false].forEach(opened => {
165-
QUnit.test(`drawer panel should ${opened ? '' : 'not'} have a hidden class before it was ${opened ? 'closed' : 'shown'} (T1239845)`, function(assert) {
166-
const $element = $('#drawer').dxDrawer({ animationDuration: 0, opened });
167-
const instance = $element.dxDrawer('instance');
168-
const $panel = $element.find(`.${DRAWER_PANEL_CONTENT_CLASS}`);
219+
QUnit.test('Drawer panel should add a hidden class after hide animation is completed, opened option is changed (T1277636)', function(assert) {
220+
const $element = $('#drawer').dxDrawer({ animationDuration: 0, opened: true });
221+
const instance = $element.dxDrawer('instance');
222+
const $panel = $element.find(`.${DRAWER_PANEL_CONTENT_CLASS}`);
169223

170-
const done = assert.async();
224+
const done = assert.async();
171225

172-
instance.toggle().then(() => {
173-
assert.strictEqual($panel.hasClass(DRAWER_PANEL_CONTENT_HIDDEN_CLASS), opened, 'dx-drawer-panel-content-hidden is not set');
174-
done();
175-
});
226+
instance.option('opened', false);
227+
228+
setTimeout(() => {
229+
assert.strictEqual($panel.hasClass(DRAWER_PANEL_CONTENT_HIDDEN_CLASS), true, 'dx-drawer-panel-content-hidden is set after animation completed');
230+
done();
231+
}, 0);
232+
233+
assert.strictEqual($panel.hasClass(DRAWER_PANEL_CONTENT_HIDDEN_CLASS), false, 'dx-drawer-panel-content-hidden is not set before animation start');
234+
});
235+
236+
QUnit.test('Drawer panel should remove a hidden class before show animation is started, toggle method is used (T1239845)', function(assert) {
237+
const $element = $('#drawer').dxDrawer({ animationDuration: 0, opened: false });
238+
const instance = $element.dxDrawer('instance');
239+
const $panel = $element.find(`.${DRAWER_PANEL_CONTENT_CLASS}`);
176240

177-
assert.strictEqual($panel.hasClass(DRAWER_PANEL_CONTENT_HIDDEN_CLASS), false, 'dx-drawer-panel-content-hidden is set');
241+
const done = assert.async();
242+
243+
instance.toggle().then(() => {
244+
assert.strictEqual($panel.hasClass(DRAWER_PANEL_CONTENT_HIDDEN_CLASS), false, 'dx-drawer-panel-content-hidden is not set after animation completed');
245+
done();
178246
});
247+
248+
assert.strictEqual($panel.hasClass(DRAWER_PANEL_CONTENT_HIDDEN_CLASS), false, 'dx-drawer-panel-content-hidden is not set before animation start');
249+
});
250+
251+
QUnit.test('Drawer panel should remove a hidden class before show animation is started, opened option is changed (T1277636)', function(assert) {
252+
const $element = $('#drawer').dxDrawer({ animationDuration: 0, opened: false });
253+
const instance = $element.dxDrawer('instance');
254+
const $panel = $element.find(`.${DRAWER_PANEL_CONTENT_CLASS}`);
255+
256+
const done = assert.async();
257+
258+
instance.option('opened', true);
259+
setTimeout(() => {
260+
assert.strictEqual($panel.hasClass(DRAWER_PANEL_CONTENT_HIDDEN_CLASS), false, 'dx-drawer-panel-content-hidden is not set after animation completed');
261+
done();
262+
}, 0);
263+
264+
assert.strictEqual($panel.hasClass(DRAWER_PANEL_CONTENT_HIDDEN_CLASS), false, 'dx-drawer-panel-content-hidden is not set before animation start');
179265
});
180266

181267
QUnit.test('Check dxresize event: opened:false,animationEnabled:true -> drawer.toggle()', function(assert) {

0 commit comments

Comments
 (0)