@anguless/angulux 22.6.1 → 22.6.2

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.
@@ -838,6 +838,12 @@ class DatePicker extends BaseInput {
838
838
  yearOptions;
839
839
  focus;
840
840
  isKeydown;
841
+ /**
842
+ * The date a time typed into a timeOnly picker is built on (#168). Kept apart from the model
843
+ * because typing empties the model on the way: "1" is not a time, so the first keystroke of
844
+ * "11:30" writes null, and by the last one the bound value's date would be gone.
845
+ */
846
+ timeOnlyDate = null;
841
847
  _minDate;
842
848
  _maxDate;
843
849
  _dateFormat;
@@ -2281,10 +2287,7 @@ class DatePicker extends BaseInput {
2281
2287
  return hours;
2282
2288
  }
2283
2289
  constrainTime(hour, minute, second, pm) {
2284
- let returnTimeTriple = [hour, minute, second];
2285
- let minHoursExceeds12 = false;
2286
2290
  let value = this.value;
2287
- const convertedHour = this.convertTo24Hour(hour, pm);
2288
2291
  const isRange = this.isRangeSelection(), isMultiple = this.isMultipleSelection(), isMultiValue = isRange || isMultiple;
2289
2292
  if (isMultiValue) {
2290
2293
  if (!this.value) {
@@ -2298,82 +2301,50 @@ class DatePicker extends BaseInput {
2298
2301
  }
2299
2302
  }
2300
2303
  const valueDateString = value && isDate(value) ? value.toDateString() : null;
2301
- let isMinDate = this.minDate && valueDateString && this.minDate.toDateString() === valueDateString;
2302
- let isMaxDate = this.maxDate && valueDateString && this.maxDate.toDateString() === valueDateString;
2304
+ const isMinDate = this.minDate && valueDateString && this.minDate.toDateString() === valueDateString;
2305
+ const isMaxDate = this.maxDate && valueDateString && this.maxDate.toDateString() === valueDateString;
2306
+ // The clamp runs on a 24-hour clock whatever the picker displays, and only the result is
2307
+ // turned back into what a 12-hour picker shows (#168).
2308
+ //
2309
+ // It used to run on the displayed hour. Every bound is read with getHours(), which is
2310
+ // 24-hour, so on a 12-hour clock the branches wrote 17 into a field that holds 1 to 12, and
2311
+ // updateTime() then added the PM offset on top: 4 PM stepped twice toward a 5 PM maximum
2312
+ // became 05:00 the NEXT DAY, and 1:45 PM stepped once toward a 1:30 PM minimum became 01:30
2313
+ // the next day. AM/PM was never set from the clamped time either, so 11 AM stepped toward
2314
+ // an 11:30 AM maximum came out as 11:30 PM. Each was written into the bound model with
2315
+ // nothing reported. Measured in e2e/upstream-repro-22-1.spec.ts.
2316
+ //
2317
+ // The rule itself is the one the 24-hour picker always applied, and still applies: a time
2318
+ // before the minimum becomes the minimum, a time after the maximum becomes the maximum,
2319
+ // compared hour, then minute, then second. (The switch this replaces said the same thing
2320
+ // through fall-through; two of its branches assigned a hard-coded 11 until 2026-09-05.)
2321
+ let time = [this.convertTo24Hour(hour, pm), minute, second];
2322
+ const compare = (a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
2303
2323
  if (isMinDate) {
2304
- minHoursExceeds12 = this.minDate.getHours() >= 12;
2305
- }
2306
- switch (true // intentional fall through
2307
- ) {
2308
- // TWO BRANCHES REMOVED HERE, both of which assigned a hard-coded 11.
2309
- //
2310
- // They read:
2311
- //
2312
- // case isMinDate && minHoursExceeds12 && minDate.getHours() === 12
2313
- // && minDate.getHours() > convertedHour:
2314
- // returnTimeTriple[0] = 11;
2315
- // case isMinDate && !minHoursExceeds12 && minDate.getHours() - 1 === convertedHour
2316
- // && minDate.getHours() > convertedHour:
2317
- // returnTimeTriple[0] = 11;
2318
- // this.pm = true;
2319
- //
2320
- // 11 is neither the minimum nor the hour the user asked for. With minDate and the
2321
- // value both at 09:00 and one step down, the second branch matched (9 - 1 === 8 and
2322
- // 9 > 8) and the picker rendered 11 — then updateTime() wrote 11:00 into the bound
2323
- // model. The application asked for a minimum of 09:00 and received a later time it
2324
- // never chose, with nothing reported. Measured in e2e/upstream-repro.spec.ts.
2325
- //
2326
- // Deleting them is safe because each condition is a STRICT SUBSET of a general
2327
- // clamp further down, and those clamps already do the right thing:
2328
- // • the first is subsumed by the minHoursExceeds12 branch below, which converts
2329
- // properly through setCurrentHourPM() instead of guessing;
2330
- // • the second is subsumed by the plain "minDate.getHours() > convertedHour"
2331
- // branch, which assigns the minimum itself.
2332
- // The minute and second lines they fell through into are repeated verbatim in both
2333
- // of those groups, so minute and second clamping is unchanged.
2334
- //
2335
- // this.pm = true was wrong on its own terms as well: that branch only ran when the
2336
- // minimum was BEFORE noon.
2337
- case isMinDate && minHoursExceeds12 && this.minDate.getHours() > convertedHour && convertedHour !== 12:
2338
- this.setCurrentHourPM(this.minDate.getHours());
2339
- returnTimeTriple[0] = this.currentHour || 0;
2340
- case isMinDate && this.minDate.getHours() === convertedHour && this.minDate.getMinutes() > minute:
2341
- returnTimeTriple[1] = this.minDate.getMinutes();
2342
- case isMinDate && this.minDate.getHours() === convertedHour && this.minDate.getMinutes() === minute && this.minDate.getSeconds() > second:
2343
- returnTimeTriple[2] = this.minDate.getSeconds();
2344
- break;
2345
- case isMinDate && this.minDate.getHours() > convertedHour:
2346
- returnTimeTriple[0] = this.minDate.getHours();
2347
- case isMinDate && this.minDate.getHours() === convertedHour && this.minDate.getMinutes() > minute:
2348
- returnTimeTriple[1] = this.minDate.getMinutes();
2349
- case isMinDate && this.minDate.getHours() === convertedHour && this.minDate.getMinutes() === minute && this.minDate.getSeconds() > second:
2350
- returnTimeTriple[2] = this.minDate.getSeconds();
2351
- break;
2352
- case isMaxDate && this.maxDate.getHours() < convertedHour:
2353
- returnTimeTriple[0] = this.maxDate.getHours();
2354
- case isMaxDate && this.maxDate.getHours() === convertedHour && this.maxDate.getMinutes() < minute:
2355
- returnTimeTriple[1] = this.maxDate.getMinutes();
2356
- case isMaxDate && this.maxDate.getHours() === convertedHour && this.maxDate.getMinutes() === minute && this.maxDate.getSeconds() < second:
2357
- returnTimeTriple[2] = this.maxDate.getSeconds();
2358
- break;
2324
+ const min = [this.minDate.getHours(), this.minDate.getMinutes(), this.minDate.getSeconds()];
2325
+ if (compare(time, min) < 0)
2326
+ time = min;
2327
+ }
2328
+ if (isMaxDate) {
2329
+ const max = [this.maxDate.getHours(), this.maxDate.getMinutes(), this.maxDate.getSeconds()];
2330
+ if (compare(time, max) > 0)
2331
+ time = max;
2359
2332
  }
2360
- return returnTimeTriple;
2333
+ if (this.hourFormat == '12') {
2334
+ this.pm = time[0] > 11;
2335
+ return [time[0] % 12 === 0 ? 12 : time[0] % 12, time[1], time[2]];
2336
+ }
2337
+ return time;
2361
2338
  }
2362
2339
  incrementHour(event) {
2363
- const prevHour = this.currentHour ?? 0;
2364
- let newHour = (this.currentHour ?? 0) + this.stepHour;
2365
- let newPM = this.pm;
2366
- if (this.hourFormat == '24')
2367
- newHour = newHour >= 24 ? newHour - 24 : newHour;
2368
- else if (this.hourFormat == '12') {
2369
- // Before the AM/PM break, now after
2370
- if (prevHour < 12 && newHour > 11) {
2371
- newPM = !this.pm;
2372
- }
2373
- newHour = newHour >= 13 ? newHour - 12 : newHour;
2374
- }
2375
- this.toggleAMPMIfNotMinDate(newPM);
2376
- [this.currentHour, this.currentMinute, this.currentSecond] = this.constrainTime(newHour, this.currentMinute, this.currentSecond, newPM);
2340
+ // The step runs on a 24-hour clock, and constrainTime() clamps the result and returns what
2341
+ // the picker displays (#168). On a 12-hour clock it used to run on the displayed hour and
2342
+ // flip AM/PM only when it passed exactly 12, so a two-hour step back from 1 PM landed on
2343
+ // 11 PM. decrementHour() is the same with the step negated.
2344
+ const twelve = this.hourFormat == '12';
2345
+ const current = twelve ? this.convertTo24Hour(this.currentHour ?? 0, !!this.pm) : (this.currentHour ?? 0);
2346
+ const next = (((current + this.stepHour) % 24) + 24) % 24;
2347
+ [this.currentHour, this.currentMinute, this.currentSecond] = this.constrainTime(twelve ? next % 12 || 12 : next, this.currentMinute, this.currentSecond, next > 11);
2377
2348
  event.preventDefault();
2378
2349
  }
2379
2350
  toggleAMPMIfNotMinDate(newPM) {
@@ -2441,19 +2412,10 @@ class DatePicker extends BaseInput {
2441
2412
  }
2442
2413
  }
2443
2414
  decrementHour(event) {
2444
- let newHour = (this.currentHour ?? 0) - this.stepHour;
2445
- let newPM = this.pm;
2446
- if (this.hourFormat == '24')
2447
- newHour = newHour < 0 ? 24 + newHour : newHour;
2448
- else if (this.hourFormat == '12') {
2449
- // If we were at noon/midnight, then switch
2450
- if (this.currentHour === 12) {
2451
- newPM = !this.pm;
2452
- }
2453
- newHour = newHour <= 0 ? 12 + newHour : newHour;
2454
- }
2455
- this.toggleAMPMIfNotMinDate(newPM);
2456
- [this.currentHour, this.currentMinute, this.currentSecond] = this.constrainTime(newHour, this.currentMinute, this.currentSecond, newPM);
2415
+ const twelve = this.hourFormat == '12';
2416
+ const current = twelve ? this.convertTo24Hour(this.currentHour ?? 0, !!this.pm) : (this.currentHour ?? 0);
2417
+ const next = (((current - this.stepHour) % 24) + 24) % 24;
2418
+ [this.currentHour, this.currentMinute, this.currentSecond] = this.constrainTime(twelve ? next % 12 || 12 : next, this.currentMinute, this.currentSecond, next > 11);
2457
2419
  event.preventDefault();
2458
2420
  }
2459
2421
  incrementMinute(event) {
@@ -2526,6 +2488,8 @@ class DatePicker extends BaseInput {
2526
2488
  return;
2527
2489
  }
2528
2490
  this.isKeydown = false;
2491
+ if (isDate(this.value))
2492
+ this.timeOnlyDate = this.value;
2529
2493
  let val = event.target.value;
2530
2494
  try {
2531
2495
  let value = this.parseValueFromString(val);
@@ -2582,7 +2546,14 @@ class DatePicker extends BaseInput {
2582
2546
  let date;
2583
2547
  let parts = text.split(' ');
2584
2548
  if (this.timeOnly) {
2585
- date = new Date();
2549
+ // A time typed into a timeOnly picker edits the time of the bound value; the date is
2550
+ // not on screen and is not the user's to lose (#168). It used to be built on new
2551
+ // Date(), so typing 11:30 over 2020-01-15 10:00 wrote TODAY at 11:30, while the hour
2552
+ // buttons on the same picker kept the date (updateTime() copies the value). The base
2553
+ // is the value, or the last date it held if typing has emptied it; with neither, or
2554
+ // with more than one value, today is still the base.
2555
+ const base = this.isSingleSelection() ? (isDate(this.value) ? this.value : this.timeOnlyDate) : null;
2556
+ date = base ? new Date(base.getTime()) : new Date();
2586
2557
  this.populateTime(date, parts[0], parts[1]);
2587
2558
  }
2588
2559
  else {
@@ -3211,6 +3182,7 @@ class DatePicker extends BaseInput {
3211
3182
  }
3212
3183
  }
3213
3184
  }
3185
+ this.timeOnlyDate = isDate(this.value) ? this.value : null;
3214
3186
  this.updateInputfield();
3215
3187
  this.updateUI();
3216
3188
  this.cd.markForCheck();
@@ -3419,6 +3391,7 @@ class DatePicker extends BaseInput {
3419
3391
  <ng-container *ngIf="date.otherMonth ? showOtherMonths : true">
3420
3392
  <span
3421
3393
  [ngClass]="dayClass(date)"
3394
+ [attr.aria-disabled]="$disabled() || !date.selectable ? true : null"
3422
3395
  (click)="onDateSelect($event, date)"
3423
3396
  draggable="false"
3424
3397
  [attr.data-date]="formatDateKey(formatDateMetaToDate(date))"
@@ -3881,6 +3854,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImpor
3881
3854
  <ng-container *ngIf="date.otherMonth ? showOtherMonths : true">
3882
3855
  <span
3883
3856
  [ngClass]="dayClass(date)"
3857
+ [attr.aria-disabled]="$disabled() || !date.selectable ? true : null"
3884
3858
  (click)="onDateSelect($event, date)"
3885
3859
  draggable="false"
3886
3860
  [attr.data-date]="formatDateKey(formatDateMetaToDate(date))"