@covalent/core 11.4.0 → 11.4.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.
package/common/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { PipeTransform, ChangeDetectorRef } from '@angular/core';
2
+ import { PipeTransform, ChangeDetectorRef, OnInit } from '@angular/core';
3
3
  import * as i10 from '@angular/forms';
4
4
  import { ControlValueAccessor, NgControl, ValidatorFn, AbstractControl } from '@angular/forms';
5
5
  import * as i11 from '@angular/common';
@@ -250,20 +250,29 @@ interface ICanDisableRipple {
250
250
  /** Mixin to augment a component or directive with a `disabled` property. */
251
251
  declare function mixinDisableRipple<T extends Constructor<Record<string, unknown>>>(base: T): Constructor<ICanDisableRipple> & T;
252
252
 
253
- declare class CovalentTextfieldValueAccessorDirective implements ControlValueAccessor {
253
+ declare class CovalentTextfieldValueAccessorDirective implements ControlValueAccessor, OnInit {
254
+ private _destroyRef;
254
255
  private _elementRef;
255
256
  _ngControl: NgControl;
256
257
  private _onChange;
257
258
  private _onTouched;
258
259
  constructor();
260
+ ngOnInit(): void;
259
261
  writeValue(value: string): void;
260
262
  registerOnChange(fn: any): void;
261
263
  registerOnTouched(fn: any): void;
262
- handleChange(event: Event): void;
264
+ /**
265
+ * Gets the updateOn strategy of the control.
266
+ * @returns The updateOn strategy of the control, defaulting to 'change' if not set.
267
+ */
268
+ private getUpdateOn;
269
+ handleInput(): void;
270
+ handleChange(): void;
263
271
  handleBlur(): void;
264
272
  setDisabledState(isDisabled: boolean): void;
265
273
  private _isCheckBox;
266
274
  private _isRadio;
275
+ private _isTextAreaOrField;
267
276
  private _updateValidity;
268
277
  static ɵfac: i0.ɵɵFactoryDeclaration<CovalentTextfieldValueAccessorDirective, never>;
269
278
  static ɵdir: i0.ɵɵDirectiveDeclaration<CovalentTextfieldValueAccessorDirective, "cv-textfield[formControl], cv-textarea[formControl], cv-select[formControl], cv-checkbox[formControl], cv-checkbox-icon[formControl], cv-radio[formControl], cv-radio-icon[formControl], cv-textfield[formControlName], cv-textarea[formControlName], cv-select[formControlName], cv-checkbox[formControlName], cv-checkbox-icon[formControlName], cv-radio[formControlName], cv-radio-icon[formControlName],", never, {}, {}, never, never, true, never>;
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { inject, Directive, HostListener, ElementRef, Pipe, Injectable, NgModule } from '@angular/core';
2
+ import { inject, Directive, HostListener, ElementRef, Pipe, Injectable, NgModule, DestroyRef } from '@angular/core';
3
3
  import { DOCUMENT, DecimalPipe, CommonModule } from '@angular/common';
4
4
  import { NgModel, FormsModule, NgControl, Validators } from '@angular/forms';
5
5
  import { MAT_ICON_DEFAULT_OPTIONS } from '@angular/material/icon';
@@ -9,6 +9,7 @@ import { filter, pairwise } from 'rxjs/operators';
9
9
  import { trigger, state, transition, style, group, query, animate, animateChild, AUTO_STYLE, keyframes } from '@angular/animations';
10
10
  import { Subject } from 'rxjs';
11
11
  import { coerceBooleanProperty } from '@angular/cdk/coercion';
12
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
12
13
 
13
14
  class TdAutoTrimDirective {
14
15
  _model = inject(NgModel, { optional: true, host: true });
@@ -2060,6 +2061,7 @@ function mixinDisableRipple(base) {
2060
2061
 
2061
2062
  /* eslint-disable @angular-eslint/directive-selector */
2062
2063
  class CovalentTextfieldValueAccessorDirective {
2064
+ _destroyRef = inject(DestroyRef);
2063
2065
  _elementRef = inject(ElementRef);
2064
2066
  _ngControl = inject(NgControl);
2065
2067
  _onChange = () => {
@@ -2072,6 +2074,16 @@ class CovalentTextfieldValueAccessorDirective {
2072
2074
  const _ngControl = this._ngControl;
2073
2075
  _ngControl.valueAccessor = this;
2074
2076
  }
2077
+ ngOnInit() {
2078
+ // Set up a subscription to monitor status changes
2079
+ if (this._ngControl.control) {
2080
+ this._ngControl.control.statusChanges
2081
+ .pipe(takeUntilDestroyed(this._destroyRef))
2082
+ .subscribe(() => {
2083
+ this._updateValidity();
2084
+ });
2085
+ }
2086
+ }
2075
2087
  writeValue(value) {
2076
2088
  if (this._isCheckBox()) {
2077
2089
  this._elementRef.nativeElement.value = value || '';
@@ -2092,15 +2104,36 @@ class CovalentTextfieldValueAccessorDirective {
2092
2104
  registerOnTouched(fn) {
2093
2105
  this._onTouched = fn;
2094
2106
  }
2095
- handleChange(event) {
2096
- const value = this._isCheckBox()
2097
- ? this._elementRef.nativeElement.checked
2098
- : this._elementRef.nativeElement.value;
2099
- this._onChange(value);
2100
- this._onTouched();
2101
- this._updateValidity();
2107
+ /**
2108
+ * Gets the updateOn strategy of the control.
2109
+ * @returns The updateOn strategy of the control, defaulting to 'change' if not set.
2110
+ */
2111
+ getUpdateOn() {
2112
+ return this._ngControl.control?.updateOn || 'change';
2113
+ }
2114
+ handleInput() {
2115
+ // Update on 'input' event for textfields/textareas if updateOn strategy is 'change'
2116
+ if (this._isTextAreaOrField() && this.getUpdateOn() === 'change') {
2117
+ const value = this._elementRef.nativeElement.value;
2118
+ this._onChange(value);
2119
+ }
2120
+ }
2121
+ handleChange() {
2122
+ // For textfields/textareas, handleInput covers 'change' event
2123
+ if (!this._isTextAreaOrField()) {
2124
+ const value = this._isCheckBox()
2125
+ ? this._elementRef.nativeElement.checked
2126
+ : this._elementRef.nativeElement.value;
2127
+ this._onChange(value);
2128
+ this._onTouched();
2129
+ }
2102
2130
  }
2103
2131
  handleBlur() {
2132
+ // For textfields/textareas, update on 'blur' if updateOn strategy is 'blur'
2133
+ if (this._isTextAreaOrField() && this.getUpdateOn() === 'blur') {
2134
+ const value = this._elementRef.nativeElement.value;
2135
+ this._onChange(value);
2136
+ }
2104
2137
  this._onTouched();
2105
2138
  }
2106
2139
  // Optional: If you need to handle disabled states
@@ -2115,6 +2148,10 @@ class CovalentTextfieldValueAccessorDirective {
2115
2148
  const tagName = this._elementRef.nativeElement.tagName.toLowerCase();
2116
2149
  return tagName === 'cv-radio' || tagName === 'cv-radio-icon';
2117
2150
  }
2151
+ _isTextAreaOrField() {
2152
+ const tagName = this._elementRef.nativeElement.tagName.toLowerCase();
2153
+ return tagName === 'cv-textarea' || tagName === 'cv-textfield';
2154
+ }
2118
2155
  _updateValidity() {
2119
2156
  const element = this._elementRef.nativeElement;
2120
2157
  const control = this._ngControl.control;
@@ -2134,7 +2171,7 @@ class CovalentTextfieldValueAccessorDirective {
2134
2171
  }
2135
2172
  static ɵfac = function CovalentTextfieldValueAccessorDirective_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || CovalentTextfieldValueAccessorDirective)(); };
2136
2173
  static ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: CovalentTextfieldValueAccessorDirective, selectors: [["cv-textfield", "formControl", ""], ["cv-textarea", "formControl", ""], ["cv-select", "formControl", ""], ["cv-checkbox", "formControl", ""], ["cv-checkbox-icon", "formControl", ""], ["cv-radio", "formControl", ""], ["cv-radio-icon", "formControl", ""], ["cv-textfield", "formControlName", ""], ["cv-textarea", "formControlName", ""], ["cv-select", "formControlName", ""], ["cv-checkbox", "formControlName", ""], ["cv-checkbox-icon", "formControlName", ""], ["cv-radio", "formControlName", ""], ["cv-radio-icon", "formControlName", ""], [""]], hostBindings: function CovalentTextfieldValueAccessorDirective_HostBindings(rf, ctx) { if (rf & 1) {
2137
- i0.ɵɵlistener("change", function CovalentTextfieldValueAccessorDirective_change_HostBindingHandler($event) { return ctx.handleChange($event); })("blur", function CovalentTextfieldValueAccessorDirective_blur_HostBindingHandler() { return ctx.handleBlur(); });
2174
+ i0.ɵɵlistener("input", function CovalentTextfieldValueAccessorDirective_input_HostBindingHandler() { return ctx.handleInput(); })("change", function CovalentTextfieldValueAccessorDirective_change_HostBindingHandler($event) { return ctx.handleChange($event); })("blur", function CovalentTextfieldValueAccessorDirective_blur_HostBindingHandler() { return ctx.handleBlur(); });
2138
2175
  } } });
2139
2176
  }
2140
2177
  (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CovalentTextfieldValueAccessorDirective, [{
@@ -2155,7 +2192,10 @@ class CovalentTextfieldValueAccessorDirective {
2155
2192
  cv-radio[formControlName],
2156
2193
  cv-radio-icon[formControlName],`,
2157
2194
  }]
2158
- }], () => [], { handleChange: [{
2195
+ }], () => [], { handleInput: [{
2196
+ type: HostListener,
2197
+ args: ['input']
2198
+ }], handleChange: [{
2159
2199
  type: HostListener,
2160
2200
  args: ['change', ['$event']]
2161
2201
  }], handleBlur: [{