@skyux/datetime 14.9.2 → 14.11.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.
|
@@ -5014,7 +5014,34 @@ const SKY_TIMEPICKER_VALIDATOR = {
|
|
|
5014
5014
|
multi: true,
|
|
5015
5015
|
};
|
|
5016
5016
|
class SkyTimepickerInputDirective {
|
|
5017
|
-
|
|
5017
|
+
constructor() {
|
|
5018
|
+
this.#_timeFormat = 'hh';
|
|
5019
|
+
/**
|
|
5020
|
+
* Whether to retain invalid entries in the input when it loses focus. When
|
|
5021
|
+
* set to `true`, an invalid value remains in the field and the associated
|
|
5022
|
+
* form control is flagged with a `skyTime` error, matching the behavior of
|
|
5023
|
+
* the datepicker.
|
|
5024
|
+
* @default false
|
|
5025
|
+
*/
|
|
5026
|
+
this.skyTimepickerRetainInvalidValues = input(false, { ...(ngDevMode ? { debugName: "skyTimepickerRetainInvalidValues" } : {}), transform: booleanAttribute });
|
|
5027
|
+
this.#_disabled = false;
|
|
5028
|
+
// Set while an invalid entry is retained on the control instead of cleared
|
|
5029
|
+
// (only when clearing invalid values is disabled).
|
|
5030
|
+
this.#hasRetainedInvalidValue = false;
|
|
5031
|
+
this.#renderer = inject(Renderer2);
|
|
5032
|
+
this.#elRef = inject(ElementRef);
|
|
5033
|
+
this.#changeDetector = inject(ChangeDetectorRef);
|
|
5034
|
+
/* istanbul ignore next */
|
|
5035
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
|
5036
|
+
this.#_onChange = (_) => { };
|
|
5037
|
+
/* istanbul ignore next */
|
|
5038
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
5039
|
+
this.#_onTouched = () => { };
|
|
5040
|
+
/* istanbul ignore next */
|
|
5041
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
5042
|
+
this.#_validatorChange = () => { };
|
|
5043
|
+
}
|
|
5044
|
+
#_timeFormat;
|
|
5018
5045
|
// TODO: In a future breaking change - grab the parent component through dependency injection and remove this setter.
|
|
5019
5046
|
// Also remove the HostBinding that references it.
|
|
5020
5047
|
/**
|
|
@@ -5061,8 +5088,11 @@ class SkyTimepickerInputDirective {
|
|
|
5061
5088
|
return this.#_modelValue;
|
|
5062
5089
|
}
|
|
5063
5090
|
set #modelValue(value) {
|
|
5064
|
-
|
|
5091
|
+
// A retained invalid entry must be cleaned up even when the model value is
|
|
5092
|
+
// unchanged (e.g. a form reset while `undefined` is the model value).
|
|
5093
|
+
if (value !== this.#_modelValue || this.#hasRetainedInvalidValue) {
|
|
5065
5094
|
this.#_modelValue = value;
|
|
5095
|
+
this.#hasRetainedInvalidValue = false;
|
|
5066
5096
|
this.#updateTimepickerInput();
|
|
5067
5097
|
this.#setInputValue(value);
|
|
5068
5098
|
this.#_validatorChange();
|
|
@@ -5070,12 +5100,15 @@ class SkyTimepickerInputDirective {
|
|
|
5070
5100
|
}
|
|
5071
5101
|
}
|
|
5072
5102
|
#control;
|
|
5073
|
-
#_disabled
|
|
5103
|
+
#_disabled;
|
|
5074
5104
|
#_modelValue;
|
|
5075
5105
|
#_skyTimepickerInput;
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
#
|
|
5106
|
+
// Set while an invalid entry is retained on the control instead of cleared
|
|
5107
|
+
// (only when clearing invalid values is disabled).
|
|
5108
|
+
#hasRetainedInvalidValue;
|
|
5109
|
+
#renderer;
|
|
5110
|
+
#elRef;
|
|
5111
|
+
#changeDetector;
|
|
5079
5112
|
ngOnInit() {
|
|
5080
5113
|
this.#renderer.addClass(this.#elRef.nativeElement, 'sky-form-control');
|
|
5081
5114
|
this.pickerChangedSubscription =
|
|
@@ -5088,7 +5121,12 @@ class SkyTimepickerInputDirective {
|
|
|
5088
5121
|
// Watch for the control to be added and initialize the value immediately.
|
|
5089
5122
|
/* istanbul ignore else */
|
|
5090
5123
|
if (this.#control && this.#control.parent) {
|
|
5091
|
-
|
|
5124
|
+
// When an invalid entry is being retained, the raw string is already on
|
|
5125
|
+
// the control and flagged invalid by the validator; overwriting it with
|
|
5126
|
+
// the (undefined) model value would discard the entry and clear the error.
|
|
5127
|
+
if (!this.#hasRetainedInvalidValue) {
|
|
5128
|
+
this.#control.setValue(this.#modelValue, { emitEvent: false });
|
|
5129
|
+
}
|
|
5092
5130
|
this.#changeDetector.markForCheck();
|
|
5093
5131
|
}
|
|
5094
5132
|
}
|
|
@@ -5124,7 +5162,18 @@ class SkyTimepickerInputDirective {
|
|
|
5124
5162
|
this.disabled = isDisabled;
|
|
5125
5163
|
}
|
|
5126
5164
|
writeValue(value) {
|
|
5127
|
-
|
|
5165
|
+
const formatted = this.#formatter(value);
|
|
5166
|
+
// When retaining is enabled, keep invalid entries in the input instead of
|
|
5167
|
+
// clearing them so the user can see and correct their entry (matching the
|
|
5168
|
+
// datepicker's behavior).
|
|
5169
|
+
if (this.skyTimepickerRetainInvalidValues() &&
|
|
5170
|
+
typeof value === 'string' &&
|
|
5171
|
+
value.length > 0 &&
|
|
5172
|
+
formatted.local === 'Invalid date') {
|
|
5173
|
+
this.#applyInvalidValue(value);
|
|
5174
|
+
return;
|
|
5175
|
+
}
|
|
5176
|
+
this.#modelValue = formatted;
|
|
5128
5177
|
}
|
|
5129
5178
|
validate(control) {
|
|
5130
5179
|
if (!this.#control) {
|
|
@@ -5134,12 +5183,35 @@ class SkyTimepickerInputDirective {
|
|
|
5134
5183
|
if (!value) {
|
|
5135
5184
|
return null;
|
|
5136
5185
|
}
|
|
5186
|
+
// A raw string value only remains on the control when retaining invalid
|
|
5187
|
+
// values is enabled.
|
|
5188
|
+
if (typeof value === 'string' && this.skyTimepickerRetainInvalidValues()) {
|
|
5189
|
+
if (this.#formatter(value).local === 'Invalid date') {
|
|
5190
|
+
// Mark as touched so the invalid CSS styles appear even when the value
|
|
5191
|
+
// is set programmatically.
|
|
5192
|
+
this.#control.markAsTouched();
|
|
5193
|
+
return { skyTime: { invalid: value } };
|
|
5194
|
+
}
|
|
5195
|
+
return null;
|
|
5196
|
+
}
|
|
5137
5197
|
/* istanbul ignore next */
|
|
5138
5198
|
if (value.local === 'Invalid date') {
|
|
5139
5199
|
return { skyTime: { invalid: control.value } };
|
|
5140
5200
|
}
|
|
5141
5201
|
return null;
|
|
5142
5202
|
}
|
|
5203
|
+
#applyInvalidValue(rawValue) {
|
|
5204
|
+
// There is no valid model value while an invalid entry is retained.
|
|
5205
|
+
this.#_modelValue = undefined;
|
|
5206
|
+
this.#hasRetainedInvalidValue = true;
|
|
5207
|
+
// Keep the user's raw entry in the input element.
|
|
5208
|
+
this.#renderer.setProperty(this.#elRef.nativeElement, 'value', rawValue);
|
|
5209
|
+
// Push the raw string to the form control and re-run validation. The
|
|
5210
|
+
// validator supplies the `skyTime` error, so we avoid calling `setErrors`
|
|
5211
|
+
// here to preserve any errors contributed by other validators.
|
|
5212
|
+
this.#_onChange(rawValue);
|
|
5213
|
+
this.#_validatorChange();
|
|
5214
|
+
}
|
|
5143
5215
|
#setInputValue(value) {
|
|
5144
5216
|
let formattedValue = '';
|
|
5145
5217
|
if (value) {
|
|
@@ -5187,15 +5259,15 @@ class SkyTimepickerInputDirective {
|
|
|
5187
5259
|
}
|
|
5188
5260
|
/* istanbul ignore next */
|
|
5189
5261
|
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
|
5190
|
-
#_onChange
|
|
5262
|
+
#_onChange;
|
|
5191
5263
|
/* istanbul ignore next */
|
|
5192
5264
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
5193
|
-
#_onTouched
|
|
5265
|
+
#_onTouched;
|
|
5194
5266
|
/* istanbul ignore next */
|
|
5195
5267
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
5196
|
-
#_validatorChange
|
|
5268
|
+
#_validatorChange;
|
|
5197
5269
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: SkyTimepickerInputDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
5198
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "
|
|
5270
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.0", type: SkyTimepickerInputDirective, isStandalone: true, selector: "[skyTimepickerInput]", inputs: { skyTimepickerInput: { classPropertyName: "skyTimepickerInput", publicName: "skyTimepickerInput", isSignal: false, isRequired: false, transformFunction: null }, timeFormat: { classPropertyName: "timeFormat", publicName: "timeFormat", isSignal: false, isRequired: false, transformFunction: null }, returnFormat: { classPropertyName: "returnFormat", publicName: "returnFormat", isSignal: false, isRequired: false, transformFunction: null }, skyTimepickerRetainInvalidValues: { classPropertyName: "skyTimepickerRetainInvalidValues", publicName: "skyTimepickerRetainInvalidValues", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: false, isRequired: false, transformFunction: null } }, host: { listeners: { "change": "onChange($event)", "blur": "onBlur()" }, properties: { "attr.skyTimepickerInput": "this.hostTimepickerInput" } }, providers: [SKY_TIMEPICKER_VALUE_ACCESSOR, SKY_TIMEPICKER_VALIDATOR], usesOnChanges: true, ngImport: i0 }); }
|
|
5199
5271
|
}
|
|
5200
5272
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: SkyTimepickerInputDirective, decorators: [{
|
|
5201
5273
|
type: Directive,
|
|
@@ -5212,7 +5284,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.0", ngImpor
|
|
|
5212
5284
|
type: Input
|
|
5213
5285
|
}], returnFormat: [{
|
|
5214
5286
|
type: Input
|
|
5215
|
-
}], disabled: [{
|
|
5287
|
+
}], skyTimepickerRetainInvalidValues: [{ type: i0.Input, args: [{ isSignal: true, alias: "skyTimepickerRetainInvalidValues", required: false }] }], disabled: [{
|
|
5216
5288
|
type: Input
|
|
5217
5289
|
}], onChange: [{
|
|
5218
5290
|
type: HostListener,
|