@quadrel-enterprise-ui/framework 20.26.0 → 20.26.1

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.
@@ -8411,10 +8411,25 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImpo
8411
8411
  }]
8412
8412
  }] });
8413
8413
 
8414
+ /**
8415
+ * Focuses its host element once, after the initial view init, when `qdAutofocus` is `true`.
8416
+ *
8417
+ * Init-only by design: the input is read in `ngAfterViewInit` only. A later `false -> true`
8418
+ * change on an already-rendered element is intentionally ignored to avoid stealing focus
8419
+ * mid-interaction (this mirrors the native `autofocus` attribute). An element that appears
8420
+ * later (e.g. via `*ngIf`) still autofocuses, because `ngAfterViewInit` runs when it is created.
8421
+ *
8422
+ * Coordinated app-wide through {@link QdAutofocusService}: only one element may autofocus per
8423
+ * view; the guard is released once the focused element blurs, so a newly opened view can
8424
+ * autofocus again. Using it on more than one active element at a time logs a warning and is
8425
+ * ignored for the surplus elements.
8426
+ */
8414
8427
  class QdAutofocusDirective {
8415
8428
  autofocusService = inject(QdAutofocusService);
8416
8429
  elementRef = inject(ElementRef);
8417
8430
  qdAutofocus = false;
8431
+ _timeoutId;
8432
+ _blurHandler;
8418
8433
  ngAfterViewInit() {
8419
8434
  if (!this.qdAutofocus)
8420
8435
  return;
@@ -8423,14 +8438,22 @@ class QdAutofocusDirective {
8423
8438
  return;
8424
8439
  }
8425
8440
  this.autofocusService.isAutofocusActivated = true;
8426
- setTimeout(() => {
8427
- this.elementRef.nativeElement.focus();
8428
- this.elementRef.nativeElement.addEventListener('blur', () => {
8441
+ this._timeoutId = setTimeout(() => {
8442
+ const element = this.elementRef.nativeElement;
8443
+ if (!element.isConnected) {
8429
8444
  this.autofocusService.isAutofocusActivated = false;
8430
- });
8445
+ return;
8446
+ }
8447
+ element.focus();
8448
+ this._blurHandler = () => void (this.autofocusService.isAutofocusActivated = false);
8449
+ element.addEventListener('blur', this._blurHandler, { once: true });
8431
8450
  }, 0);
8432
8451
  }
8433
8452
  ngOnDestroy() {
8453
+ if (this._timeoutId)
8454
+ clearTimeout(this._timeoutId);
8455
+ if (this._blurHandler)
8456
+ this.elementRef.nativeElement.removeEventListener('blur', this._blurHandler);
8434
8457
  this.autofocusService.isAutofocusActivated = false;
8435
8458
  }
8436
8459
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: QdAutofocusDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });