ng-zenduit 2.2.4 → 2.2.5
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/fesm2022/ng-zenduit.mjs +34 -10
- package/fesm2022/ng-zenduit.mjs.map +1 -1
- package/package.json +1 -1
- package/types/ng-zenduit.d.ts +1 -0
package/fesm2022/ng-zenduit.mjs
CHANGED
|
@@ -7405,10 +7405,26 @@ class ZenduDatePickerDropdownComponent {
|
|
|
7405
7405
|
&& this.endDate.getTime() === this._appliedPresetEndTime) {
|
|
7406
7406
|
return this._translate.instant(this._appliedPresetLabel);
|
|
7407
7407
|
}
|
|
7408
|
+
// Show the preset name when the range matches one
|
|
7409
|
+
const presetLabel = this.matchingPresetLabel(this.startDate, this.endDate);
|
|
7410
|
+
if (presetLabel) {
|
|
7411
|
+
return this._translate.instant(presetLabel);
|
|
7412
|
+
}
|
|
7408
7413
|
return `${this.formatDate(this.startDate)} - ${this.formatDate(this.endDate)}`;
|
|
7409
7414
|
}
|
|
7410
7415
|
return this.placeholder || this._translate.instant('Select dates');
|
|
7411
7416
|
}
|
|
7417
|
+
matchingPresetLabel(start, end) {
|
|
7418
|
+
for (const preset of this.activePresets) {
|
|
7419
|
+
const range = preset.getRange();
|
|
7420
|
+
if (range.start && range.end
|
|
7421
|
+
&& moment(start).isSame(range.start, 'day')
|
|
7422
|
+
&& moment(end).isSame(range.end, 'day')) {
|
|
7423
|
+
return preset.label;
|
|
7424
|
+
}
|
|
7425
|
+
}
|
|
7426
|
+
return null;
|
|
7427
|
+
}
|
|
7412
7428
|
get legendMarkers() {
|
|
7413
7429
|
return (this.dateMarkers || []).filter(m => !!m.title);
|
|
7414
7430
|
}
|
|
@@ -7481,22 +7497,30 @@ class ZenduDatePickerDropdownComponent {
|
|
|
7481
7497
|
updateDropdownPosition() {
|
|
7482
7498
|
if (!this.triggerBtn)
|
|
7483
7499
|
return;
|
|
7484
|
-
|
|
7485
|
-
|
|
7500
|
+
// Place below the trigger synchronously so the panel opens without a flash
|
|
7501
|
+
const rect = this.triggerBtn.nativeElement.getBoundingClientRect();
|
|
7502
|
+
this.dropdownStyle = {
|
|
7503
|
+
left: `${rect.left}px`,
|
|
7504
|
+
top: `${rect.bottom + 8}px`
|
|
7505
|
+
};
|
|
7506
|
+
// Once rendered, flip above or pin to the viewport if it overflows
|
|
7507
|
+
requestAnimationFrame(() => {
|
|
7486
7508
|
const dropdownEl = this._element.nativeElement.querySelector('.dropdown-menu');
|
|
7487
|
-
|
|
7488
|
-
|
|
7489
|
-
const
|
|
7509
|
+
if (!dropdownEl)
|
|
7510
|
+
return;
|
|
7511
|
+
const r = this.triggerBtn.nativeElement.getBoundingClientRect();
|
|
7512
|
+
const dropdownHeight = dropdownEl.scrollHeight;
|
|
7513
|
+
const spaceBelow = window.innerHeight - r.bottom - 8;
|
|
7514
|
+
const spaceAbove = r.top - 8;
|
|
7490
7515
|
const margin = 16;
|
|
7491
7516
|
const viewportHeight = window.innerHeight;
|
|
7492
|
-
const style = { left: `${rect.left}px` };
|
|
7493
7517
|
if (spaceBelow >= dropdownHeight) {
|
|
7494
|
-
|
|
7495
|
-
style['top'] = `${rect.bottom + 8}px`;
|
|
7518
|
+
return;
|
|
7496
7519
|
}
|
|
7497
|
-
|
|
7520
|
+
const style = { left: `${r.left}px` };
|
|
7521
|
+
if (spaceAbove >= dropdownHeight) {
|
|
7498
7522
|
// Fits above the trigger
|
|
7499
|
-
style['bottom'] = `${viewportHeight -
|
|
7523
|
+
style['bottom'] = `${viewportHeight - r.top + 8}px`;
|
|
7500
7524
|
}
|
|
7501
7525
|
else {
|
|
7502
7526
|
// Doesn't fit either way — pin to viewport so full content is visible
|