@skyux/datetime 15.0.0-alpha.3 → 15.0.0-alpha.4

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.
@@ -5071,8 +5071,11 @@ class SkyTimepickerInputDirective {
5071
5071
  return this.#_modelValue;
5072
5072
  }
5073
5073
  set #modelValue(value) {
5074
- if (value !== this.#_modelValue) {
5074
+ // A retained invalid entry must be cleaned up even when the model value is
5075
+ // unchanged (e.g. a form reset while `undefined` is the model value).
5076
+ if (value !== this.#_modelValue || this.#hasRetainedInvalidValue) {
5075
5077
  this.#_modelValue = value;
5078
+ this.#hasRetainedInvalidValue = false;
5076
5079
  this.#updateTimepickerInput();
5077
5080
  this.#setInputValue(value);
5078
5081
  this.#_validatorChange();
@@ -5083,6 +5086,8 @@ class SkyTimepickerInputDirective {
5083
5086
  #_disabled = false;
5084
5087
  #_modelValue;
5085
5088
  #_skyTimepickerInput;
5089
+ // Set while an invalid entry is retained on the control instead of cleared.
5090
+ #hasRetainedInvalidValue = false;
5086
5091
  #renderer = inject(Renderer2);
5087
5092
  #elRef = inject(ElementRef);
5088
5093
  #changeDetector = inject(ChangeDetectorRef);
@@ -5098,7 +5103,12 @@ class SkyTimepickerInputDirective {
5098
5103
  // Watch for the control to be added and initialize the value immediately.
5099
5104
  /* istanbul ignore else */
5100
5105
  if (this.#control && this.#control.parent) {
5101
- this.#control.setValue(this.#modelValue, { emitEvent: false });
5106
+ // When an invalid entry is being retained, the raw string is already on
5107
+ // the control and flagged invalid by the validator; overwriting it with
5108
+ // the (undefined) model value would discard the entry and clear the error.
5109
+ if (!this.#hasRetainedInvalidValue) {
5110
+ this.#control.setValue(this.#modelValue, { emitEvent: false });
5111
+ }
5102
5112
  this.#changeDetector.markForCheck();
5103
5113
  }
5104
5114
  }
@@ -5134,7 +5144,16 @@ class SkyTimepickerInputDirective {
5134
5144
  this.disabled = isDisabled;
5135
5145
  }
5136
5146
  writeValue(value) {
5137
- this.#modelValue = this.#formatter(value);
5147
+ const formatted = this.#formatter(value);
5148
+ // Keep invalid entries in the input instead of clearing them so the user
5149
+ // can see and correct their entry (matching the datepicker's behavior).
5150
+ if (typeof value === 'string' &&
5151
+ value.length > 0 &&
5152
+ formatted.local === 'Invalid date') {
5153
+ this.#applyInvalidValue(value);
5154
+ return;
5155
+ }
5156
+ this.#modelValue = formatted;
5138
5157
  }
5139
5158
  validate(control) {
5140
5159
  if (!this.#control) {
@@ -5144,12 +5163,35 @@ class SkyTimepickerInputDirective {
5144
5163
  if (!value) {
5145
5164
  return null;
5146
5165
  }
5166
+ // A raw string value only remains on the control when it could not be
5167
+ // parsed into a time and was retained as-is.
5168
+ if (typeof value === 'string') {
5169
+ if (this.#formatter(value).local === 'Invalid date') {
5170
+ // Mark as touched so the invalid CSS styles appear even when the value
5171
+ // is set programmatically.
5172
+ this.#control.markAsTouched();
5173
+ return { skyTime: { invalid: value } };
5174
+ }
5175
+ return null;
5176
+ }
5147
5177
  /* istanbul ignore next */
5148
5178
  if (value.local === 'Invalid date') {
5149
5179
  return { skyTime: { invalid: control.value } };
5150
5180
  }
5151
5181
  return null;
5152
5182
  }
5183
+ #applyInvalidValue(rawValue) {
5184
+ // There is no valid model value while an invalid entry is retained.
5185
+ this.#_modelValue = undefined;
5186
+ this.#hasRetainedInvalidValue = true;
5187
+ // Keep the user's raw entry in the input element.
5188
+ this.#renderer.setProperty(this.#elRef.nativeElement, 'value', rawValue);
5189
+ // Push the raw string to the form control and re-run validation. The
5190
+ // validator supplies the `skyTime` error, so we avoid calling `setErrors`
5191
+ // here to preserve any errors contributed by other validators.
5192
+ this.#_onChange(rawValue);
5193
+ this.#_validatorChange();
5194
+ }
5153
5195
  #setInputValue(value) {
5154
5196
  let formattedValue = '';
5155
5197
  if (value) {