Skip to content

Instantly share code, notes, and snippets.

@xcambar
Created April 20, 2018 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xcambar/1f797e56f6a21c6985b5212a596c02cc to your computer and use it in GitHub Desktop.
Save xcambar/1f797e56f6a21c6985b5212a596c02cc to your computer and use it in GitHub Desktop.
ember-modal-dialog: double onClose call
import Ember from 'ember';
export default Ember.Controller.extend({
countClose: 0,
incCloseCount() {
this.incrementProperty('countClose');
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.ember-modal-overlay {
background: rgba(128, 128, 128, .2);
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
<h1 {{action (mut openModal) true}}>click to open a modal</h1>
{{#if openModal}}
{{#modal-dialog
clickOutsideToClose=true
onClose=(action incCloseCount)}}
Click anywhere to close the modal.
{{/modal-dialog}}
{{/if}}
"onClose" has been called {{countClose}} times.
<hr>
<h3>Why?</h3>
In its default implementation, "onClickOverlay" calls "onClose". When an overlay is used in addition with "clickOutsideToClose" (which calls "onClose"), the addon does the following:
<ul>
<li>Calling "onClickOverlay", hence calling "onClose"</li>
<li>Calling "onClose" because of "onClickOutsideToClose"</li>
</ul>
As a consequence, "onClose" is called twice in such (common, I think) configuration.
{
"version": "0.13.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3",
"ember-modal-dialog": "2.4.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment