Skip to content

Commit

Permalink
Ensure closeAction is correctly called if clicking outside
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Novy committed Apr 24, 2017
1 parent 0823a0d commit 338c575
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions addon/components/date-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const {
set,
Component,
A: array,
typeOf: getTypeOf
typeOf: getTypeOf,
run
} = Ember;

/**
Expand Down Expand Up @@ -177,7 +178,7 @@ export default Component.extend({
closeAction: null,

/**
* Whether the calendar displays the week starting on Monday or Sunday.
* Whether the calendar displays the week starting on Mondayf or Sunday.
*
* @attribute startWeekOnSunday
* @type {Boolean}
Expand Down Expand Up @@ -557,17 +558,23 @@ export default Component.extend({
set(this, 'isOpen', false);
set(this, 'isToStep', false);

if (sendAction) {
run.once(this, this._sendCloseAction);
}

if (forceCloseDropdown) {
this._closeDropdown();
}
},

_sendCloseAction() {
let action = get(this, 'attrs.closeAction');
let vals = get(this, '_dates');
let isRange = get(this, 'range');

if (sendAction && action) {
if (action) {
action(isRange ? vals : vals[0] || null);
}

if (forceCloseDropdown) {
this._closeDropdown();
}
},

_closeDropdown() {
Expand Down Expand Up @@ -823,7 +830,7 @@ export default Component.extend({
},

closeDropdown() {
this._close(false, false);
this._close(true, false);
},

openDropdown(dropdownApi) {
Expand Down

0 comments on commit 338c575

Please sign in to comment.