@wernfried/daterangepicker 5.5.2 → 5.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/API_Doc.md CHANGED
@@ -694,7 +694,7 @@ Options for DateRangePicker
694
694
  | timePicker24Hour | <code>boolean</code> | | Use 24-hour instead of 12-hour times, removing the AM/PM selection.<br> Default is derived from current locale [Intl.DateTimeFormat.resolvedOptions.hour12](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions#hour12). |
695
695
  | timePickerStepSize | [<code>Duration</code>](https://moment.github.io/luxon/api-docs/index.html#duration) \| <code>string</code> \| <code>number</code> | | Default: `Duration.fromObject({minutes:1})`<br>Set the time picker step size.<br> Must be a `luxon.Duration` or the number of seconds or a string according to [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) duration.<br> Valid values are 1,2,3,4,5,6,10,12,15,20,30 for `Duration.fromObject({seconds: ...})` and `Duration.fromObject({minutes: ...})` and 1,2,3,4,6,(8,12) for `Duration.fromObject({hours: ...})`.<br> Duration must be greater than `minSpan` and smaller than `maxSpan`.<br> For example `timePickerStepSize: 600` will disable time picker seconds and time picker minutes are set to step size of 10 Minutes. |
696
696
  | autoUpdateInput | <code>boolean</code> | <code>true</code> | Indicates whether the DateRangePicker should instantly update the value of the attached `<input>` element when the selected dates change.<br>The `<input>` element will be always updated on `Apply` and reverted when user clicks on `Cancel`. |
697
- | onOutsideClick | <code>string</code> | <code>&quot;apply&quot;</code> | Defines what picker shall do when user clicks outside the calendar. `'apply'` or `'cancel'`. Event [onOutsideClick](#event_outsideClick) is always emitted.return; If you like to do nothing (i.e. neither `apply` nor `cancel`), call `event.preventDefault()` in the event listener. |
697
+ | onOutsideClick | <code>string</code> | <code>&quot;apply&quot;</code> | Defines what picker shall do when user clicks outside the calendar. `cancel`, `apply` or `hide`. Event [onOutsideClick](#event_outsideClick) is always emitted;<br> `cancel` reverts to previous date values. Note, `apply` is only useful with `autoApply: false`, otherwise date values will apply multiple times<br> If you like to do nothing, call `event.preventDefault()` in the event listener. |
698
698
  | linkedCalendars | <code>boolean</code> | <code>true</code> | When enabled, the two calendars displayed will always be for two sequential months (i.e. January and February), and both will be advanced when clicking the left or right arrows above the calendars.<br> When disabled, the two calendars can be individually advanced and display any month/year |
699
699
  | isInvalidDate | <code>function</code> | <code>false</code> | A function that is passed each date in the two calendars before they are displayed,<br> and may return `true` or `false` to indicate whether that date should be available for selection or not.<br> Signature: `isInvalidDate(date)`<br> |
700
700
  | isInvalidTime | <code>function</code> | <code>false</code> | A function that is passed each hour/minute/second/am-pm in the two calendars before they are displayed,<br> and may return `true` or `false` to indicate whether that date should be available for selection or not.<br> Signature: `isInvalidTime(time, side, unit)`<br> `side` is `'start'` or `'end'` or `null` for `singleDatePicker: true`<br> `unit` is `'hour'`, `'minute'`, `'second'` or `'ampm'`<br> Hours are always given as 24-hour clock<br> Ensure that your function returns `false` for at least one item. Otherwise the calender is not rendered.<br> |
package/README.md CHANGED
@@ -372,7 +372,7 @@ Options for DateRangePicker
372
372
  | timePicker24Hour | <code>boolean</code> | | Use 24-hour instead of 12-hour times, removing the AM/PM selection.<br> Default is derived from current locale [Intl.DateTimeFormat.resolvedOptions.hour12](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions#hour12). |
373
373
  | timePickerStepSize | [<code>Duration</code>](https://moment.github.io/luxon/api-docs/index.html#duration) \| <code>string</code> \| <code>number</code> | | Default: `Duration.fromObject({minutes:1})`<br>Set the time picker step size.<br> Must be a `luxon.Duration` or the number of seconds or a string according to [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) duration.<br> Valid values are 1,2,3,4,5,6,10,12,15,20,30 for `Duration.fromObject({seconds: ...})` and `Duration.fromObject({minutes: ...})` and 1,2,3,4,6,(8,12) for `Duration.fromObject({hours: ...})`.<br> Duration must be greater than `minSpan` and smaller than `maxSpan`.<br> For example `timePickerStepSize: 600` will disable time picker seconds and time picker minutes are set to step size of 10 Minutes. |
374
374
  | autoUpdateInput | <code>boolean</code> | <code>true</code> | Indicates whether the DateRangePicker should instantly update the value of the attached `<input>` element when the selected dates change.<br>The `<input>` element will be always updated on `Apply` and reverted when user clicks on `Cancel`. |
375
- | onOutsideClick | <code>string</code> | <code>&quot;apply&quot;</code> | Defines what picker shall do when user clicks outside the calendar. `'apply'` or `'cancel'`. Event [onOutsideClick](#event_outsideClick) is always emitted.return; If you like to do nothing (i.e. neither `apply` nor `cancel`), call `event.preventDefault()` in the event listener. |
375
+ | onOutsideClick | <code>string</code> | <code>&quot;apply&quot;</code> | Defines what picker shall do when user clicks outside the calendar. `cancel`, `apply` or `hide`. Event [onOutsideClick](#event_outsideClick) is always emitted;<br> `cancel` reverts to previous date values. Note, `apply` is only useful with `autoApply: false`, otherwise date values will apply multiple times<br> If you like to do nothing, call `event.preventDefault()` in the event listener. |
376
376
  | linkedCalendars | <code>boolean</code> | <code>true</code> | When enabled, the two calendars displayed will always be for two sequential months (i.e. January and February), and both will be advanced when clicking the left or right arrows above the calendars.<br> When disabled, the two calendars can be individually advanced and display any month/year |
377
377
  | isInvalidDate | <code>function</code> | <code>false</code> | A function that is passed each date in the two calendars before they are displayed,<br> and may return `true` or `false` to indicate whether that date should be available for selection or not.<br> Signature: `isInvalidDate(date)`<br> |
378
378
  | isInvalidTime | <code>function</code> | <code>false</code> | A function that is passed each hour/minute/second/am-pm in the two calendars before they are displayed,<br> and may return `true` or `false` to indicate whether that date should be available for selection or not.<br> Signature: `isInvalidTime(time, side, unit)`<br> `side` is `'start'` or `'end'` or `null` for `singleDatePicker: true`<br> `unit` is `'hour'`, `'minute'`, `'second'` or `'ampm'`<br> Hours are always given as 24-hour clock<br> Ensure that your function returns `false` for at least one item. Otherwise the calender is not rendered.<br> |
@@ -454,10 +454,10 @@ class DateRangePicker {
454
454
  this.buttonClasses = options.buttonClasses;
455
455
  }
456
456
  if (typeof options.onOutsideClick === "string") {
457
- if (["cancel", "apply"].includes(options.onOutsideClick))
457
+ if (["cancel", "apply", "hide"].includes(options.onOutsideClick))
458
458
  this.onOutsideClick = options.onOutsideClick;
459
459
  else
460
- console.error(`Option 'onOutsideClick' must be 'cancel' or 'apply'`);
460
+ console.error(`Option 'onOutsideClick' must be 'cancel', 'apply' or 'hide'`);
461
461
  }
462
462
  if (this.locale.firstDay != 1) {
463
463
  let iterator = this.locale.firstDay;
@@ -1698,14 +1698,10 @@ class DateRangePicker {
1698
1698
  */
1699
1699
  hide() {
1700
1700
  if (!this.isShowing) return;
1701
- if (!this.#endDate) {
1701
+ if (!this.#endDate && !this.singleDatePicker) {
1702
1702
  this.#startDate = this.oldStartDate;
1703
1703
  this.#endDate = this.oldEndDate;
1704
1704
  }
1705
- if (typeof this.callback === "function") {
1706
- if (this.#startDate && !this.#startDate.equals(this.oldStartDate ?? luxon.DateTime) || this.#endDate && !this.singleDatePicker && !this.#endDate.equals(this.oldEndDate ?? luxon.DateTime))
1707
- this.callback(this.startDate, this.endDate, this.chosenLabel);
1708
- }
1709
1705
  this.updateElement();
1710
1706
  const event = this.triggerEvent(this.#events.onBeforeHide);
1711
1707
  if (event.defaultPrevented)
@@ -1777,8 +1773,12 @@ class DateRangePicker {
1777
1773
  if (this.onOutsideClick === "cancel") {
1778
1774
  this.#startDate = this.oldStartDate;
1779
1775
  this.#endDate = this.oldEndDate;
1776
+ this.hide();
1777
+ } else if (this.onOutsideClick === "apply") {
1778
+ this.clickApply();
1779
+ } else {
1780
+ this.hide();
1780
1781
  }
1781
- this.hide();
1782
1782
  }
1783
1783
  /**
1784
1784
  * Move calendar to previous month
@@ -2141,6 +2141,11 @@ class DateRangePicker {
2141
2141
  * @private
2142
2142
  */
2143
2143
  clickApply() {
2144
+ this.updateElement();
2145
+ if (typeof this.callback === "function") {
2146
+ if (this.#startDate && (this.#endDate || !this.singleDatePicker))
2147
+ this.callback(this.startDate, this.endDate, this.chosenLabel);
2148
+ }
2144
2149
  this.hide();
2145
2150
  this.triggerEvent(this.#events.onApply);
2146
2151
  }