@brightspace-ui/core 3.329.0 → 3.330.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.
@@ -57,9 +57,7 @@ The `<d2l-input-text>` element is a simple wrapper around the native `<input typ
57
57
  | `instructions` | String | Additional information relating to how to use the component |
58
58
  | `label-hidden` | Boolean | Hides the label visually (moves it to the input's `aria-label` attribute) |
59
59
  | `labelled-by` | String | HTML id of an element in the same shadow root which acts as the input's label |
60
- | `max` | String | For number inputs, maximum value |
61
60
  | `maxlength` | Number | Imposes an upper character limit |
62
- | `min` | String | For number inputs, minimum value |
63
61
  | `minlength` | Number | Imposes a lower character limit |
64
62
  | `name` | String | Name of the form control. Submitted with the form as part of a name/value pair. |
65
63
  | `novalidate` | Boolean | Disables the built-in validation |
@@ -70,7 +68,7 @@ The `<d2l-input-text>` element is a simple wrapper around the native `<input typ
70
68
  | `required` | Boolean | Indicates that a value is required |
71
69
  | `size` | Number | Size of the input |
72
70
  | `step` | String | For number inputs, sets the step size |
73
- | `type` | String, default: `text` | Can be one of `text`, `email`, `password`, `tel`, `url`. Type `number` is deprecated, use [d2l-input-number](./input-numeric.md) instead. |
71
+ | `type` | String, default: `text` | Can be one of `text`, `email`, `password`, `tel`, `url` |
74
72
  | `unit` | String | Unit associated with the input value, displayed next to input and announced as part of the label |
75
73
  | `value` | String, default: `''` | Value of the input |
76
74
 
@@ -309,18 +309,13 @@ class InputDate extends FocusMixin(LabelledMixin(SkeletonMixin(FormElementMixin(
309
309
  super.updated(changedProperties);
310
310
 
311
311
  changedProperties.forEach((oldVal, prop) => {
312
- if (prop === '_dateTimeDescriptor' || prop === 'value') {
313
- this._shownValue = this.value;
314
- this._setFormattedValue();
315
-
316
- if (prop === 'value') {
317
- this.setFormValue(this.value);
318
- this.setValidity({
319
- rangeUnderflow: !this.noValidateMinMax && this.value && this.minValue && getDateFromISODate(this.value).getTime() < getDateFromISODate(this.minValue).getTime(),
320
- rangeOverflow: !this.noValidateMinMax && this.value && this.maxValue && getDateFromISODate(this.value).getTime() > getDateFromISODate(this.maxValue).getTime()
321
- });
322
- this.requestValidate(false);
323
- }
312
+ if (prop === 'value') {
313
+ this.setFormValue(this.value);
314
+ this.setValidity({
315
+ rangeUnderflow: !this.noValidateMinMax && this.value && this.minValue && getDateFromISODate(this.value).getTime() < getDateFromISODate(this.minValue).getTime(),
316
+ rangeOverflow: !this.noValidateMinMax && this.value && this.maxValue && getDateFromISODate(this.value).getTime() > getDateFromISODate(this.maxValue).getTime()
317
+ });
318
+ this.requestValidate(false);
324
319
  } else if (prop === 'opened') {
325
320
  if (this.opened) this._open();
326
321
  else this._close();
@@ -333,6 +328,10 @@ class InputDate extends FocusMixin(LabelledMixin(SkeletonMixin(FormElementMixin(
333
328
  willUpdate(changedProperties) {
334
329
  super.willUpdate(changedProperties);
335
330
  if (changedProperties.has('_hiddenContentWidth')) this.style.maxWidth = this.inputTextWidth;
331
+ if (changedProperties.has('_dateTimeDescriptor') || changedProperties.has('value')) {
332
+ this._shownValue = this.value;
333
+ this._setFormattedValue();
334
+ }
336
335
  }
337
336
 
338
337
  async validate() {
@@ -397,38 +396,31 @@ class InputDate extends FocusMixin(LabelledMixin(SkeletonMixin(FormElementMixin(
397
396
  this.requestValidate(true);
398
397
  }
399
398
 
400
- async _handleChange() {
399
+ _handleChange() {
401
400
  this._showRevertTooltip = false;
402
401
  const value = this._textInput.value;
403
402
  const isNewVal = value !== this.value;
404
403
  if (!value && !this.required) {
405
404
  if (isNewVal) {
406
- await this._updateValueDispatchEvent('');
407
- if (this._calendar) {
408
- await this.updateComplete;
409
- await this._calendar.reset();
410
- }
405
+ this._updateValueDispatchEvent('');
406
+ this.calendar?.reset();
411
407
  }
412
408
  return;
413
409
  }
414
- this._formattedValue = value;
415
- await this.updateComplete;
416
410
  try {
417
411
  const date = parseDate(value);
418
- await this._updateValueDispatchEvent(formatDateInISO({ year: date.getFullYear(), month: (parseInt(date.getMonth()) + 1), date: date.getDate() }));
412
+ this._updateValueDispatchEvent(formatDateInISO({ year: date.getFullYear(), month: (parseInt(date.getMonth()) + 1), date: date.getDate() }));
419
413
  } catch {
420
414
  // leave value the same when invalid input
421
415
  if (isNewVal) this._showRevertTooltip = true;
416
+ this._textInput.value = this._formattedValue; // Template only reset if property changes, this line forces same prop on live value
422
417
  }
423
418
  this._setFormattedValue(); // keep out here in case parseDate is same date, e.g., user adds invalid text to end of parseable date
424
- if (this._calendar) {
425
- await this.updateComplete;
426
- await this._calendar.reset(true);
427
- }
419
+ this._calendar?.reset(true);
428
420
  }
429
421
 
430
422
  async _handleClear() {
431
- await this._updateValueDispatchEvent('');
423
+ this._updateValueDispatchEvent('');
432
424
  if (this._dropdown) {
433
425
  this._dropdown.close();
434
426
  }
@@ -438,7 +430,7 @@ class InputDate extends FocusMixin(LabelledMixin(SkeletonMixin(FormElementMixin(
438
430
  async _handleDateSelected(e) {
439
431
  this._showRevertTooltip = false;
440
432
  const value = e.target.selectedValue;
441
- await this._updateValueDispatchEvent(value);
433
+ this._updateValueDispatchEvent(value);
442
434
  if (this._dropdown) {
443
435
  this._dropdown.close();
444
436
  }
@@ -484,6 +476,7 @@ class InputDate extends FocusMixin(LabelledMixin(SkeletonMixin(FormElementMixin(
484
476
  await this.updateComplete;
485
477
  if (!this.shadowRoot) return;
486
478
  this._calendar = this.shadowRoot.querySelector('d2l-calendar');
479
+ await this._calendar.reset(true);
487
480
  this._dropdown = this.shadowRoot.querySelector('d2l-dropdown-content');
488
481
  await this._calendar.updateComplete;
489
482
  }
@@ -534,7 +527,7 @@ class InputDate extends FocusMixin(LabelledMixin(SkeletonMixin(FormElementMixin(
534
527
 
535
528
  async _handleSetToToday(_, setToNow) {
536
529
  const date = getToday();
537
- await this._updateValueDispatchEvent(formatDateInISO(date), setToNow);
530
+ this._updateValueDispatchEvent(formatDateInISO(date), setToNow);
538
531
  if (this._dropdown) {
539
532
  this._dropdown.close();
540
533
  }
@@ -543,10 +536,9 @@ class InputDate extends FocusMixin(LabelledMixin(SkeletonMixin(FormElementMixin(
543
536
 
544
537
  async _open() {
545
538
  if (this.disabled || this.skeleton) return;
539
+ this._handleChange();
546
540
  if (!this._dropdownFirstOpened || !this._dropdown) await this._handleFirstDropdownOpen();
547
541
 
548
- await this._handleChange();
549
-
550
542
  // on small screens, only open calendar if calendar icon is selected,
551
543
  // otherwise only open text input
552
544
  if (mediaQueryList.matches && this._openCalendarOnly) {
@@ -570,10 +562,14 @@ class InputDate extends FocusMixin(LabelledMixin(SkeletonMixin(FormElementMixin(
570
562
  }
571
563
 
572
564
  _setFormattedValue() {
573
- this._formattedValue = this._shownValue ? formatISODateInUserCalDescriptor(this._shownValue) : '';
565
+ try {
566
+ this._formattedValue = this._shownValue ? formatISODateInUserCalDescriptor(this._shownValue) : '';
567
+ } catch {
568
+ // don't set the value if it's invalid
569
+ }
574
570
  }
575
571
 
576
- async _updateValueDispatchEvent(dateInISO, setToNow) {
572
+ _updateValueDispatchEvent(dateInISO, setToNow) {
577
573
  // prevent validation from happening multiple times for same change,
578
574
  // except for now button that affects time
579
575
  if (!setToNow && dateInISO === this._shownValue) return;
@@ -85,21 +85,11 @@ class InputText extends InputInlineHelpMixin(PropertyRequiredMixin(FocusMixin(La
85
85
  * @type {boolean}
86
86
  */
87
87
  labelHidden: { type: Boolean, attribute: 'label-hidden' },
88
- /**
89
- * For number inputs, maximum value
90
- * @type {string}
91
- */
92
- max: { type: String },
93
88
  /**
94
89
  * Imposes an upper character limit
95
90
  * @type {number}
96
91
  */
97
92
  maxlength: { type: Number },
98
- /**
99
- * For number inputs, minimum value
100
- * @type {string}
101
- */
102
- min: { type: String },
103
93
  /**
104
94
  * Imposes a lower character limit
105
95
  * @type {number}
@@ -150,7 +140,7 @@ class InputText extends InputInlineHelpMixin(PropertyRequiredMixin(FocusMixin(La
150
140
  title: { type: String },
151
141
  /**
152
142
  * The type of the text input
153
- * @type {'text'|'email'|'number'|'password'|'search'|'tel'|'url'}
143
+ * @type {'text'|'email'|'password'|'search'|'tel'|'url'}
154
144
  */
155
145
  type: { type: String },
156
146
  /**
@@ -328,11 +318,7 @@ class InputText extends InputInlineHelpMixin(PropertyRequiredMixin(FocusMixin(La
328
318
 
329
319
  /** @ignore */
330
320
  get validationMessage() {
331
- if (this.validity.rangeOverflow) {
332
- return this.localize('components.form-element.input.number.rangeOverflow', { max: formatNumber(parseFloat(this.max)), maxExclusive: false });
333
- } else if (this.validity.rangeUnderflow) {
334
- return this.localize('components.form-element.input.number.rangeUnderflow', { min: formatNumber(parseFloat(this.min)), minExclusive: false });
335
- } else if (this.validity.tooShort) {
321
+ if (this.validity.tooShort) {
336
322
  return this.localize('components.form-element.input.text.tooShort', { label: this.label, minlength: formatNumber(this.minlength) });
337
323
  } else if (this.validity.typeMismatch) {
338
324
  if (this.type === 'email') {
@@ -469,9 +455,7 @@ class InputText extends InputInlineHelpMixin(PropertyRequiredMixin(FocusMixin(La
469
455
  @input="${this._handleInput}"
470
456
  @invalid="${this._handleInvalid}"
471
457
  @keypress="${this._handleKeypress}"
472
- max="${ifDefined(this.max)}"
473
458
  maxlength="${ifDefined(this.maxlength)}"
474
- min="${ifDefined(this.min)}"
475
459
  minlength="${ifDefined(this.minlength)}"
476
460
  name="${ifDefined(this.name)}"
477
461
  pattern="${ifDefined(this.pattern)}"
@@ -532,6 +516,14 @@ class InputText extends InputInlineHelpMixin(PropertyRequiredMixin(FocusMixin(La
532
516
  });
533
517
  }
534
518
 
519
+ willUpdate(changedProperties) {
520
+ super.willUpdate(changedProperties);
521
+ if (changedProperties.has('type') && this.type === 'number') {
522
+ this.type = 'text';
523
+ console.warn('d2l-input-text: "number" type is not supported, use d2l-input-number instead. Defaulting to "text"');
524
+ }
525
+ }
526
+
535
527
  #handleBlur = async(e) => {
536
528
  this._focused = false;
537
529
  this.requestValidate(true);
@@ -564,7 +556,7 @@ class InputText extends InputInlineHelpMixin(PropertyRequiredMixin(FocusMixin(La
564
556
  }
565
557
 
566
558
  _getType() {
567
- if (this.type === 'email' || this.type === 'number' || this.type === 'password' || this.type === 'tel' || this.type === 'text' || this.type === 'search' || this.type === 'url') {
559
+ if (this.type === 'email' || this.type === 'password' || this.type === 'tel' || this.type === 'text' || this.type === 'search' || this.type === 'url') {
568
560
  return this.type;
569
561
  }
570
562
  return 'text';
@@ -8296,21 +8296,11 @@
8296
8296
  "description": "ADVANCED: Additional information relating to how to use the component",
8297
8297
  "type": "string"
8298
8298
  },
8299
- {
8300
- "name": "max",
8301
- "description": "For number inputs, maximum value",
8302
- "type": "string"
8303
- },
8304
8299
  {
8305
8300
  "name": "maxlength",
8306
8301
  "description": "Imposes an upper character limit",
8307
8302
  "type": "number"
8308
8303
  },
8309
- {
8310
- "name": "min",
8311
- "description": "For number inputs, minimum value",
8312
- "type": "string"
8313
- },
8314
8304
  {
8315
8305
  "name": "minlength",
8316
8306
  "description": "Imposes a lower character limit",
@@ -8396,7 +8386,7 @@
8396
8386
  {
8397
8387
  "name": "type",
8398
8388
  "description": "The type of the text input",
8399
- "type": "'text'|'email'|'number'|'password'|'search'|'tel'|'url'",
8389
+ "type": "'text'|'email'|'password'|'search'|'tel'|'url'",
8400
8390
  "default": "\"text\""
8401
8391
  },
8402
8392
  {
@@ -8463,24 +8453,12 @@
8463
8453
  "description": "ADVANCED: Additional information relating to how to use the component",
8464
8454
  "type": "string"
8465
8455
  },
8466
- {
8467
- "name": "max",
8468
- "attribute": "max",
8469
- "description": "For number inputs, maximum value",
8470
- "type": "string"
8471
- },
8472
8456
  {
8473
8457
  "name": "maxlength",
8474
8458
  "attribute": "maxlength",
8475
8459
  "description": "Imposes an upper character limit",
8476
8460
  "type": "number"
8477
8461
  },
8478
- {
8479
- "name": "min",
8480
- "attribute": "min",
8481
- "description": "For number inputs, minimum value",
8482
- "type": "string"
8483
- },
8484
8462
  {
8485
8463
  "name": "minlength",
8486
8464
  "attribute": "minlength",
@@ -8592,7 +8570,7 @@
8592
8570
  "name": "type",
8593
8571
  "attribute": "type",
8594
8572
  "description": "The type of the text input",
8595
- "type": "'text'|'email'|'number'|'password'|'search'|'tel'|'url'",
8573
+ "type": "'text'|'email'|'password'|'search'|'tel'|'url'",
8596
8574
  "default": "\"text\""
8597
8575
  },
8598
8576
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.329.0",
3
+ "version": "3.330.0",
4
4
  "description": "A collection of accessible, free, open-source web components for building Brightspace applications",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/BrightspaceUI/core.git",