ng-hub-ui-forms 22.43.0 → 22.44.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.
package/README.md CHANGED
@@ -148,7 +148,7 @@ npm install ng-hub-ui-forms ng-hub-ui-utils ng-hub-ui-ds
148
148
  "@angular/forms": ">=21.0.0",
149
149
  "@angular/platform-browser": ">=21.0.0",
150
150
  "ng-hub-ui-ds": ">=22.14.1",
151
- "ng-hub-ui-utils": ">=22.12.0"
151
+ "ng-hub-ui-utils": ">=22.21.0"
152
152
  }
153
153
  ```
154
154
 
@@ -843,6 +843,13 @@ form = new FormGroup(
843
843
  On submit, each invalid field shows its error and the cross-field `hubAreEqual`
844
844
  error is surfaced by the fieldset/form — no manual error markup anywhere.
845
845
 
846
+ Inside a container that lays fields out as cells, a message under the control would make the
847
+ row taller. Such a container provides `HUB_FIELD_FEEDBACK` (from `ng-hub-ui-utils`) with
848
+ `'tooltip'`, and the fields inside it ring themselves in the danger colour and keep the message
849
+ for a tooltip on hover, in the danger colour with white or black text by contrast. The message
850
+ stays in the page, visually hidden, so screen readers still announce it. The paginable table does
851
+ this under `flushFields`, and the spreadsheet for the fields it opens in a cell.
852
+
846
853
  #### Taking the reader to the errors
847
854
 
848
855
  `hubScrollToError` on the submit button scrolls to the first error left on screen and focuses its
@@ -1,10 +1,10 @@
1
1
  import * as i0 from '@angular/core';
2
- import { input, model, Directive, inject, TemplateRef, InjectionToken, makeEnvironmentProviders, ElementRef, ChangeDetectorRef, contentChild, contentChildren, computed, signal, effect, booleanAttribute, numberAttribute, output, DestroyRef, viewChild, isDevMode, linkedSignal, afterRenderEffect, ViewEncapsulation, ChangeDetectionStrategy, Component, viewChildren, PLATFORM_ID, afterNextRender, Injectable, Renderer2, NgZone, afterEveryRender, HostAttributeToken, forwardRef, Injector, HostListener, LOCALE_ID, ViewContainerRef, untracked, Pipe } from '@angular/core';
2
+ import { input, model, Directive, inject, TemplateRef, InjectionToken, makeEnvironmentProviders, ElementRef, ChangeDetectorRef, contentChild, contentChildren, computed, signal, afterEveryRender, DestroyRef, effect, booleanAttribute, numberAttribute, output, viewChild, isDevMode, linkedSignal, afterRenderEffect, ViewEncapsulation, ChangeDetectionStrategy, Component, viewChildren, PLATFORM_ID, afterNextRender, Injectable, Renderer2, NgZone, HostAttributeToken, forwardRef, Injector, HostListener, LOCALE_ID, ViewContainerRef, untracked, Pipe } from '@angular/core';
3
3
  import * as i1 from '@angular/forms';
4
4
  import { FormControlName, FormControlDirective, Validators, FormControl, NgControl, ControlContainer, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
5
5
  import { Subject, takeUntil, tap, Observable, animationFrameScheduler, asapScheduler, fromEvent } from 'rxjs';
6
+ import { HUB_FIELD_FEEDBACK, HubTooltipController, parseColor, readableOn, toHex, HubTooltipDirective, resolveHubAccent, OverlayService, HUB_DROPDOWN_POSITIONS } from 'ng-hub-ui-utils';
6
7
  import { NgTemplateOutlet, KeyValuePipe, isPlatformBrowser, DOCUMENT, formatDate } from '@angular/common';
7
- import { parseColor, readableOn, toHex, HubTooltipDirective, resolveHubAccent, OverlayService, HUB_DROPDOWN_POSITIONS } from 'ng-hub-ui-utils';
8
8
  import { auditTime, tap as tap$1, debounceTime, filter, map } from 'rxjs/operators';
9
9
  import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
10
10
  import { DomSanitizer } from '@angular/platform-browser';
@@ -759,6 +759,9 @@ class HubFieldControl extends HubFormControl {
759
759
  _elementRef = inject(ElementRef);
760
760
  #config = inject(HUB_FORMS_CONFIG);
761
761
  #cdr = inject(ChangeDetectorRef);
762
+ #feedbackPlacement = inject(HUB_FIELD_FEEDBACK, { optional: true });
763
+ /** Built on the first render that has a message to carry, and never for a field that shows it below. */
764
+ #feedbackTooltip = null;
762
765
  _control = inject(NgControl, { self: true, optional: true });
763
766
  _controlContainer = inject(ControlContainer, { skipSelf: true, host: true, optional: true });
764
767
  /** Resolved templates that override the default message of a given error key. */
@@ -811,6 +814,13 @@ class HubFieldControl extends HubFormControl {
811
814
  */
812
815
  showsFormTextTooltip = computed(() => this.formTextType() === FormTextTypes.Tooltip && !!this.formText(), /* @ts-ignore */
813
816
  ...(ngDevMode ? [{ debugName: "showsFormTextTooltip" }] : /* istanbul ignore next */ []));
817
+ /**
818
+ * Whether a container above asked for the validation message as a tooltip
819
+ * (see `HUB_FIELD_FEEDBACK`). The message block stays in the page, out of sight, so it is
820
+ * still announced; the field marks itself in the danger colour instead.
821
+ */
822
+ feedbackAsTooltip = computed(() => this.#feedbackPlacement?.() === 'tooltip', /* @ts-ignore */
823
+ ...(ngDevMode ? [{ debugName: "feedbackAsTooltip" }] : /* istanbul ignore next */ []));
814
824
  onChange = () => { };
815
825
  onTouched = () => { };
816
826
  _nativeErrors = signal(null, /* @ts-ignore */
@@ -822,6 +832,26 @@ class HubFieldControl extends HubFormControl {
822
832
  if (this._control) {
823
833
  this._control.valueAccessor = this;
824
834
  }
835
+ afterEveryRender(() => this.#syncFeedbackTooltip());
836
+ inject(DestroyRef).onDestroy(() => this.#feedbackTooltip?.destroy());
837
+ }
838
+ /**
839
+ * Hands the rendered message to the tooltip. Read off the DOM rather than rebuilt from the
840
+ * errors, so projected `hubValidationError` templates and HTML messages come through as the
841
+ * text the reader would have seen under the control.
842
+ */
843
+ #syncFeedbackTooltip() {
844
+ if (!this.feedbackAsTooltip()) {
845
+ this.#feedbackTooltip?.setText('');
846
+ return;
847
+ }
848
+ const host = this._elementRef.nativeElement;
849
+ const message = this.isInvalid
850
+ ? (host.querySelector('.hub-field__feedback[role="alert"]')?.textContent ?? '').replace(/\s+/g, ' ').trim()
851
+ : '';
852
+ if (message || this.#feedbackTooltip) {
853
+ (this.#feedbackTooltip ??= new HubTooltipController(host)).setText(message);
854
+ }
825
855
  }
826
856
  /** Whether the field should display its error feedback (touched + invalid). */
827
857
  get isInvalid() {
@@ -934,13 +964,14 @@ class HubFieldControl extends HubFormControl {
934
964
  this._nativeErrors.set(isDefined$1(errors) && Object.keys(errors).length ? errors : null);
935
965
  }
936
966
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: HubFieldControl, deps: [], target: i0.ɵɵFactoryTarget.Directive });
937
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "22.0.8", type: HubFieldControl, isStandalone: true, inputs: { formText: { classPropertyName: "formText", publicName: "formText", isSignal: true, isRequired: false, transformFunction: null }, formTextType: { classPropertyName: "formTextType", publicName: "formTextType", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, invalidFeedbackTemplateFn: { classPropertyName: "invalidFeedbackTemplateFn", publicName: "invalidFeedbackTemplateFn", isSignal: true, isRequired: false, transformFunction: null }, showValid: { classPropertyName: "showValid", publicName: "showValid", isSignal: true, isRequired: false, transformFunction: null }, validFeedback: { classPropertyName: "validFeedback", publicName: "validFeedback", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { disabled: "disabledChange" }, host: { listeners: { "focusout": "handleBlur($event)" } }, queries: [{ propertyName: "formTextTmp", first: true, predicate: HubFormTextDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "errorTpts", predicate: HubValidationErrorDirective, isSignal: true }], usesInheritance: true, ngImport: i0 });
967
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "22.0.8", type: HubFieldControl, isStandalone: true, inputs: { formText: { classPropertyName: "formText", publicName: "formText", isSignal: true, isRequired: false, transformFunction: null }, formTextType: { classPropertyName: "formTextType", publicName: "formTextType", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, invalidFeedbackTemplateFn: { classPropertyName: "invalidFeedbackTemplateFn", publicName: "invalidFeedbackTemplateFn", isSignal: true, isRequired: false, transformFunction: null }, showValid: { classPropertyName: "showValid", publicName: "showValid", isSignal: true, isRequired: false, transformFunction: null }, validFeedback: { classPropertyName: "validFeedback", publicName: "validFeedback", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { disabled: "disabledChange" }, host: { listeners: { "focusout": "handleBlur($event)" }, properties: { "class.hub-field-host--feedback-tooltip": "feedbackAsTooltip()" } }, queries: [{ propertyName: "formTextTmp", first: true, predicate: HubFormTextDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "errorTpts", predicate: HubValidationErrorDirective, isSignal: true }], usesInheritance: true, ngImport: i0 });
938
968
  }
939
969
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: HubFieldControl, decorators: [{
940
970
  type: Directive,
941
971
  args: [{
942
972
  host: {
943
- '(focusout)': 'handleBlur($event)'
973
+ '(focusout)': 'handleBlur($event)',
974
+ '[class.hub-field-host--feedback-tooltip]': 'feedbackAsTooltip()'
944
975
  }
945
976
  }]
946
977
  }], ctorParameters: () => [], propDecorators: { formTextTmp: [{ type: i0.ContentChild, args: [i0.forwardRef(() => HubFormTextDirective), { ...{ read: TemplateRef }, isSignal: true }] }], formText: [{ type: i0.Input, args: [{ isSignal: true, alias: "formText", required: false }] }], formTextType: [{ type: i0.Input, args: [{ isSignal: true, alias: "formTextType", required: false }] }], errorTpts: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => HubValidationErrorDirective), { isSignal: true }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }, { type: i0.Output, args: ["disabledChange"] }], invalidFeedbackTemplateFn: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalidFeedbackTemplateFn", required: false }] }], showValid: [{ type: i0.Input, args: [{ isSignal: true, alias: "showValid", required: false }] }], validFeedback: [{ type: i0.Input, args: [{ isSignal: true, alias: "validFeedback", required: false }] }] } });