Skip to content

Commit

Permalink
Merge pull request #412 from simplabs/modal-count
Browse files Browse the repository at this point in the history
fix backdrop not animating immediately after the last modal is closed
  • Loading branch information
nickschot authored Jul 16, 2021
2 parents 7abd248 + c9c820d commit dd122c2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
9 changes: 8 additions & 1 deletion addon/modal.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// eslint-disable-next-line ember/no-computed-properties-in-native-classes
import { computed, set } from '@ember/object';
import { waitForPromise } from '@ember/test-waiters';

import { defer } from 'rsvp';
Expand All @@ -18,6 +20,11 @@ export default class Modal {
return this._result;
}

@computed('_deferredOutAnimation')
get isClosing() {
return Boolean(this._deferredOutAnimation);
}

close(result) {
if (this._componentInstance) {
this._componentInstance.closeModal(result);
Expand All @@ -30,7 +37,7 @@ export default class Modal {

_resolve(result) {
if (!this._deferredOutAnimation) {
this._deferredOutAnimation = defer();
set(this, '_deferredOutAnimation', defer());

this._result = result;
this._deferred.resolve(result);
Expand Down
6 changes: 4 additions & 2 deletions addon/services/modals.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { A } from '@ember/array';
import { set } from '@ember/object';
import { computed, set } from '@ember/object';
import { alias } from '@ember/object/computed';
import Service from '@ember/service';

import Modal from '../modal';

export default Service.extend({
count: alias('_stack.length'),
count: computed('[email protected]', function () {
return this._stack.filter(modal => !modal.isClosing).length;
}),
top: alias('_stack.lastObject'),

clickOutsideDeactivates: true,
Expand Down
2 changes: 2 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = async function () {
npm: {
devDependencies: {
'ember-source': '~3.4.0',
'ember-decorators-polyfill': '^1.1.5',
},
},
},
Expand All @@ -19,6 +20,7 @@ module.exports = async function () {
npm: {
devDependencies: {
'ember-source': '~3.8.0',
'ember-decorators-polyfill': '^1.1.5',
},
},
},
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/services/modals-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,19 @@ module('Service | modals', function (hooks) {

modal._remove();
});

test('modals do not show up in openCount when closing', async function (assert) {
let modals = this.owner.lookup('service:modals');
let modal = modals.open('modal');

assert.equal(modals.count, 1);

modal._resolve();

assert.equal(modals.count, 0);

modal._remove();

assert.equal(modals.count, 0);
});
});

0 comments on commit dd122c2

Please sign in to comment.