@momentum-design/components 0.142.5 → 0.142.7

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.
@@ -105,6 +105,8 @@ class Calendar extends KeyDownHandledMixin(KeyToActionMixin(Component)) {
105
105
  if (dt) {
106
106
  this.displayMonth = dt.getMonth() + 1;
107
107
  this.displayYear = dt.getFullYear();
108
+ if (!this.gridHasFocus)
109
+ this.focusedDate = this.value;
108
110
  }
109
111
  }
110
112
  }
@@ -294,6 +296,8 @@ class Calendar extends KeyDownHandledMixin(KeyToActionMixin(Component)) {
294
296
  }));
295
297
  }
296
298
  handleGridKeydown(event) {
299
+ if (event.altKey || event.ctrlKey || event.metaKey)
300
+ return;
297
301
  const focusDt = this.focusedDate ? parseISO(this.focusedDate) : today();
298
302
  if (!focusDt)
299
303
  return;
@@ -443,8 +447,11 @@ class Calendar extends KeyDownHandledMixin(KeyToActionMixin(Component)) {
443
447
  </div>
444
448
  `;
445
449
  }
446
- handleGridFocusIn() {
450
+ handleGridFocusIn(event) {
447
451
  this.gridHasFocus = true;
452
+ const target = event.target;
453
+ if (target.dataset.date)
454
+ this.focusedDate = target.dataset.date;
448
455
  }
449
456
  handleGridFocusOut() {
450
457
  this.gridHasFocus = false;
@@ -201,6 +201,7 @@ declare class DatePicker extends DatePicker_base implements AssociatedFormContro
201
201
  private getFieldValue;
202
202
  private setFieldValue;
203
203
  private handleSpinbuttonKeydown;
204
+ private handleSpinbuttonInput;
204
205
  private handleDigitInput;
205
206
  private advanceToNextField;
206
207
  private advanceToPrevField;
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  import { html, nothing } from 'lit';
11
11
  import { property, query, state } from 'lit/decorators.js';
12
12
  import { ifDefined } from 'lit/directives/if-defined.js';
13
+ import { live } from 'lit/directives/live.js';
13
14
  import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
14
15
  import { FormInternalsMixin } from '../../utils/mixins/FormInternalsMixin';
15
16
  import { parseISO, isBefore, isAfter } from '../../utils/date-utils';
@@ -187,7 +188,8 @@ class DatePicker extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)
187
188
  }
188
189
  }
189
190
  if (changedProperties.has('value') && !this.displayPopover) {
190
- this.parseValueToInternal();
191
+ if (this.value !== this.internalToValue())
192
+ this.parseValueToInternal();
191
193
  this.syncFormValue();
192
194
  }
193
195
  else if (changedProperties.has('endValue') && !this.displayPopover) {
@@ -313,6 +315,11 @@ class DatePicker extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)
313
315
  this.syncFormValue();
314
316
  this.notifyValueChange();
315
317
  }
318
+ else if (this.value) {
319
+ this.value = '';
320
+ this.syncFormValue();
321
+ this.notifyValueChange();
322
+ }
316
323
  }
317
324
  notifyValueChange() {
318
325
  const detail = { value: this.value, endValue: this.endValue };
@@ -449,7 +456,7 @@ class DatePicker extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)
449
456
  }
450
457
  setFieldValue(field, val) {
451
458
  const maxDigits = field === 'year' ? 4 : 2;
452
- const padded = String(val).padStart(maxDigits, '0');
459
+ const padded = val === '' ? '' : String(val).padStart(maxDigits, '0');
453
460
  switch (field) {
454
461
  case 'month':
455
462
  this.internalMonth = padded;
@@ -466,6 +473,8 @@ class DatePicker extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)
466
473
  this.requestUpdate();
467
474
  }
468
475
  handleSpinbuttonKeydown(event, field) {
476
+ if (event.altKey || event.ctrlKey || event.metaKey)
477
+ return;
469
478
  if (this.disabled || this.softDisabled || this.readonly) {
470
479
  if (event.key === KEYS.ARROW_UP || event.key === KEYS.ARROW_DOWN)
471
480
  event.preventDefault();
@@ -501,16 +510,45 @@ class DatePicker extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)
501
510
  case KEYS.TAB:
502
511
  break;
503
512
  default: {
504
- if (/^\d$/.test(event.key)) {
513
+ if (event.key.length === 1 && !/^\d$/.test(event.key)) {
505
514
  event.preventDefault();
506
- this.handleDigitInput(event.key, field, range.min, range.max);
515
+ }
516
+ break;
517
+ }
518
+ }
519
+ }
520
+ handleSpinbuttonInput(event, field) {
521
+ var _a;
522
+ if (this.preventSoftDisabledChange(event, this.getFieldValue(field)))
523
+ return;
524
+ event.stopPropagation();
525
+ if (this.disabled || this.readonly || event.isComposing)
526
+ return;
527
+ const input = event.target;
528
+ const range = this.getFieldRange(field);
529
+ if (event.data && /^\d+$/.test(event.data)) {
530
+ if (event.inputType === 'insertReplacementText')
531
+ this.pendingDigits = '';
532
+ this.handleDigitInput(event.data, field, range.min, range.max);
533
+ }
534
+ else {
535
+ if (this.pendingDigitTimeout)
536
+ clearTimeout(this.pendingDigitTimeout);
537
+ this.pendingDigits = '';
538
+ if (/^\d*$/.test(input.value)) {
539
+ const digits = input.value.slice(0, field === 'year' ? 4 : 2);
540
+ if (digits && !((_a = event.inputType) === null || _a === void 0 ? void 0 : _a.startsWith('delete'))) {
541
+ this.handleDigitInput(digits, field, range.min, range.max);
507
542
  }
508
543
  else {
509
- event.preventDefault();
544
+ const value = digits ? Math.min(range.max, Math.max(range.min, parseInt(digits, 10))) : '';
545
+ this.setFieldValue(field, value);
546
+ this.commitValue();
510
547
  }
511
- break;
512
548
  }
513
549
  }
550
+ // Native input can change the DOM even when the reactive value stays the same.
551
+ this.requestUpdate();
514
552
  }
515
553
  handleDigitInput(digit, field, minVal, maxVal) {
516
554
  if (this.pendingDigitTimeout) {
@@ -673,17 +711,20 @@ class DatePicker extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)
673
711
  aria-valuemin="${range.min}"
674
712
  aria-valuemax="${range.max}"
675
713
  aria-valuenow="${ifDefined(value ? parseInt(value, 10) : undefined)}"
714
+ aria-valuetext="${ifDefined(value ? String(parseInt(value, 10)) : undefined)}"
676
715
  aria-description="${this.localeSpinbuttonDescription}"
677
- .value="${value}"
716
+ .value="${live(value)}"
717
+ inputmode="numeric"
678
718
  placeholder="${placeholderMap[field]}"
679
719
  autocomplete="off"
680
720
  ?disabled="${this.disabled}"
681
721
  ?readonly="${this.readonly}"
682
722
  aria-disabled="${this.disabled || this.softDisabled}"
683
723
  @beforeinput="${this.preventSoftDisabledInput}"
684
- @input="${(event) => this.preventSoftDisabledChange(event, value)}"
685
724
  tabindex="${this.disabled ? '-1' : '0'}"
686
725
  @keydown="${(e) => this.handleSpinbuttonKeydown(e, field)}"
726
+ @input="${(e) => this.handleSpinbuttonInput(e, field)}"
727
+ @change="${(e) => e.stopPropagation()}"
687
728
  @focus="${this.handleSpinbuttonFocus}"
688
729
  />
689
730
  `;