@vaadin/date-picker 23.1.9 → 23.1.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/date-picker",
3
- "version": "23.1.9",
3
+ "version": "23.1.11",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -34,19 +34,19 @@
34
34
  "dependencies": {
35
35
  "@open-wc/dedupe-mixin": "^1.3.0",
36
36
  "@polymer/polymer": "^3.2.0",
37
- "@vaadin/button": "~23.1.9",
38
- "@vaadin/component-base": "~23.1.9",
39
- "@vaadin/field-base": "~23.1.9",
40
- "@vaadin/input-container": "~23.1.9",
41
- "@vaadin/vaadin-lumo-styles": "~23.1.9",
42
- "@vaadin/vaadin-material-styles": "~23.1.9",
43
- "@vaadin/vaadin-overlay": "~23.1.9",
44
- "@vaadin/vaadin-themable-mixin": "~23.1.9"
37
+ "@vaadin/button": "~23.1.11",
38
+ "@vaadin/component-base": "~23.1.11",
39
+ "@vaadin/field-base": "~23.1.11",
40
+ "@vaadin/input-container": "~23.1.11",
41
+ "@vaadin/vaadin-lumo-styles": "~23.1.11",
42
+ "@vaadin/vaadin-material-styles": "~23.1.11",
43
+ "@vaadin/vaadin-overlay": "~23.1.11",
44
+ "@vaadin/vaadin-themable-mixin": "~23.1.11"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@esm-bundle/chai": "^4.3.4",
48
48
  "@vaadin/testing-helpers": "^0.3.2",
49
49
  "sinon": "^13.0.2"
50
50
  },
51
- "gitHead": "ad8461e09f049c3f04f50278d38d0f5a98604904"
51
+ "gitHead": "8431798f6d50c35193817be868ddee0de021166c"
52
52
  }
@@ -318,6 +318,18 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
318
318
  return this.getAttribute('dir') === 'rtl';
319
319
  }
320
320
 
321
+ /**
322
+ * Whether to scroll to a sub-month position when scrolling to a date.
323
+ * This is active if the month scroller is not large enough to fit a
324
+ * full month. In that case we want to scroll to a position between
325
+ * two months in order to have the focused date in the visible area.
326
+ * @returns {boolean} whether to use sub-month scrolling
327
+ * @private
328
+ */
329
+ get __useSubMonthScrolling() {
330
+ return this.$.monthScroller.clientHeight < this.$.monthScroller.itemHeight + this.$.monthScroller.bufferOffset;
331
+ }
332
+
321
333
  get focusableDateElement() {
322
334
  return [...this.shadowRoot.querySelectorAll('vaadin-month-calendar')]
323
335
  .map((calendar) => calendar.focusableDateElement)
@@ -374,7 +386,9 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
374
386
  * Scrolls the list to the given Date.
375
387
  */
376
388
  scrollToDate(date, animate) {
377
- this._scrollToPosition(this._differenceInMonths(date, this._originDate), animate);
389
+ const offset = this.__useSubMonthScrolling ? this._calculateWeekScrollOffset(date) : 0;
390
+ this._scrollToPosition(this._differenceInMonths(date, this._originDate) + offset, animate);
391
+ this.$.monthScroller.forceUpdate();
378
392
  }
379
393
 
380
394
  /**
@@ -406,23 +420,63 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
406
420
  * Scrolls the month and year scrollers enough to reveal the given date.
407
421
  */
408
422
  revealDate(date, animate = true) {
409
- if (date) {
410
- const diff = this._differenceInMonths(date, this._originDate);
411
- const scrolledAboveViewport = this.$.monthScroller.position > diff;
412
-
413
- const visibleArea = Math.max(
414
- this.$.monthScroller.itemHeight,
415
- this.$.monthScroller.clientHeight - this.$.monthScroller.bufferOffset * 2,
416
- );
417
- const visibleItems = visibleArea / this.$.monthScroller.itemHeight;
418
- const scrolledBelowViewport = this.$.monthScroller.position + visibleItems - 1 < diff;
419
-
420
- if (scrolledAboveViewport) {
421
- this._scrollToPosition(diff, animate);
422
- } else if (scrolledBelowViewport) {
423
- this._scrollToPosition(diff - visibleItems + 1, animate);
423
+ if (!date) {
424
+ return;
425
+ }
426
+ const diff = this._differenceInMonths(date, this._originDate);
427
+ // If scroll area does not fit the full month, then always scroll with an offset to
428
+ // approximately display the week of the date
429
+ if (this.__useSubMonthScrolling) {
430
+ const offset = this._calculateWeekScrollOffset(date);
431
+ this._scrollToPosition(diff + offset, animate);
432
+ return;
433
+ }
434
+
435
+ // Otherwise determine if we need to scroll to make the month of the date visible
436
+ const scrolledAboveViewport = this.$.monthScroller.position > diff;
437
+
438
+ const visibleArea = Math.max(
439
+ this.$.monthScroller.itemHeight,
440
+ this.$.monthScroller.clientHeight - this.$.monthScroller.bufferOffset * 2,
441
+ );
442
+ const visibleItems = visibleArea / this.$.monthScroller.itemHeight;
443
+ const scrolledBelowViewport = this.$.monthScroller.position + visibleItems - 1 < diff;
444
+
445
+ if (scrolledAboveViewport) {
446
+ this._scrollToPosition(diff, animate);
447
+ } else if (scrolledBelowViewport) {
448
+ this._scrollToPosition(diff - visibleItems + 1, animate);
449
+ }
450
+ }
451
+
452
+ /**
453
+ * Calculates an offset to be added to the month scroll position
454
+ * when using sub-month scrolling, in order ensure that the week
455
+ * that the date is in is visible even for small scroll areas.
456
+ * As the month scroller uses a month as minimal scroll unit
457
+ * (a value of `1` equals one month), we can not exactly identify
458
+ * the position of a specific week. This is a best effort
459
+ * implementation based on manual testing.
460
+ * @param date the date for which to calculate the offset
461
+ * @returns {number} the offset
462
+ * @private
463
+ */
464
+ _calculateWeekScrollOffset(date) {
465
+ // Get first day of month
466
+ const temp = new Date(0, 0);
467
+ temp.setFullYear(date.getFullYear());
468
+ temp.setMonth(date.getMonth());
469
+ temp.setDate(1);
470
+ // Determine week (=row index) of date within the month
471
+ let week = 0;
472
+ while (temp.getDate() < date.getDate()) {
473
+ temp.setDate(temp.getDate() + 1);
474
+ if (temp.getDay() === this.i18n.firstDayOfWeek) {
475
+ week += 1;
424
476
  }
425
477
  }
478
+ // Calculate magic number that approximately keeps the week visible
479
+ return week / 6;
426
480
  }
427
481
 
428
482
  _initialPositionChanged(initialPosition) {
@@ -680,10 +734,6 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
680
734
  return months - date2.getMonth() + date1.getMonth();
681
735
  }
682
736
 
683
- _differenceInYears(date1, date2) {
684
- return this._differenceInMonths(date1, date2) / 12;
685
- }
686
-
687
737
  _clear() {
688
738
  this._selectDate('');
689
739
  }
@@ -10,11 +10,6 @@ export const datePickerStyles = css`
10
10
  direction: ltr;
11
11
  }
12
12
 
13
- :host([dir='rtl']) [part='value']::placeholder {
14
- direction: rtl;
15
- text-align: left;
16
- }
17
-
18
13
  :host([dir='rtl']) [part='input-field'] ::slotted(input)::placeholder {
19
14
  direction: rtl;
20
15
  text-align: left;
@@ -143,6 +143,18 @@ class InfiniteScroller extends PolymerElement {
143
143
  }
144
144
  }
145
145
 
146
+ /**
147
+ * Force the scroller to update clones after a reset, without
148
+ * waiting for the debouncer to resolve.
149
+ */
150
+ forceUpdate() {
151
+ if (this._debouncerUpdateClones) {
152
+ this._buffers[0].updated = this._buffers[1].updated = false;
153
+ this._updateClones();
154
+ this._debouncerUpdateClones.cancel();
155
+ }
156
+ }
157
+
146
158
  _activated(active) {
147
159
  if (active && !this._initialized) {
148
160
  this._createPool();
@@ -426,12 +426,6 @@ class MonthCalendar extends FocusMixin(ThemableMixin(PolymerElement)) {
426
426
 
427
427
  return '-1';
428
428
  }
429
-
430
- __getWeekNumbers(dates) {
431
- return dates
432
- .map((date) => this.__getWeekNumber(date, dates))
433
- .filter((week, index, arr) => arr.indexOf(week) === index);
434
- }
435
429
  }
436
430
 
437
431
  customElements.define(MonthCalendar.is, MonthCalendar);
@@ -37,7 +37,7 @@ registerStyles(
37
37
  + var(--lumo-size-m) * 6
38
38
  + var(--lumo-space-s)
39
39
  );
40
- --vaadin-infinite-scroller-buffer-offset: 20%;
40
+ --vaadin-infinite-scroller-buffer-offset: 10%;
41
41
  -webkit-mask-image: linear-gradient(transparent, #000 10%, #000 85%, transparent);
42
42
  mask-image: linear-gradient(transparent, #000 10%, #000 85%, transparent);
43
43
  position: relative;
@@ -132,11 +132,6 @@ registerStyles(
132
132
  background: var(--material-background-color);
133
133
  }
134
134
 
135
- :host([years-visible]) [part='years']::after {
136
- top: calc(20px + 16px);
137
- height: calc(100% - 20px - 16px);
138
- }
139
-
140
135
  [part='year-number'] {
141
136
  font-size: var(--material-small-font-size);
142
137
  line-height: 10px; /* NOTE(platosha): chosen to align years to months */