@siemens/element-ng 51.5.0 → 51.6.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.
@@ -1,6 +1,6 @@
1
1
  import { formatDate, DatePipe } from '@angular/common';
2
2
  import * as i0 from '@angular/core';
3
- import { input, model, output, viewChild, inject, Injector, afterNextRender, computed, Component, signal, Directive, LOCALE_ID, DestroyRef, untracked, booleanAttribute, ElementRef, viewChildren, ChangeDetectionStrategy, NgModule } from '@angular/core';
3
+ import { input, model, output, viewChild, inject, Injector, computed, afterNextRender, Component, signal, Directive, LOCALE_ID, DestroyRef, untracked, booleanAttribute, ElementRef, viewChildren, ChangeDetectionStrategy, NgModule } from '@angular/core';
4
4
  import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
5
5
  import { elementCancel, elementSearch } from '@siemens/element-icons';
6
6
  import { defaultConnectedOverlayScrollStrategyFactory, isRTL } from '@siemens/element-ng/common';
@@ -128,7 +128,7 @@ class SiFilteredSearchInputComponent {
128
128
  /** Public method to focus the input element */
129
129
  focus() {
130
130
  this.inputElement().nativeElement.focus();
131
- afterNextRender(() => this.typeahead().updateOverlayPosition(), { injector: this.injector });
131
+ this.updateOverlayPositionAfterRender();
132
132
  }
133
133
  typeaheadCreateOption = computed(() => this.freeTextCriterion() && !this.maxCriteriaReached() && this.allowFreeText()
134
134
  ? this.searchForFreeTextLabel()
@@ -149,6 +149,7 @@ class SiFilteredSearchInputComponent {
149
149
  }
150
150
  const tokens = inputElement.value.split(';');
151
151
  let consumedTokenCount = 0;
152
+ let createdCriterion = false;
152
153
  for (const [index, token] of tokens.entries()) {
153
154
  const isLastToken = index === tokens.length - 1;
154
155
  const criterionMatch = token.match(SiFilteredSearchInputComponent.criterionRegex);
@@ -168,10 +169,14 @@ class SiFilteredSearchInputComponent {
168
169
  if (!accepted) {
169
170
  break;
170
171
  }
172
+ createdCriterion = true;
171
173
  consumedTokenCount++;
172
174
  }
173
175
  inputElement.value = tokens.slice(consumedTokenCount).join(';');
174
176
  this.searchValue.set(inputElement.value);
177
+ if (createdCriterion) {
178
+ this.updateOverlayPositionAfterRender();
179
+ }
175
180
  }
176
181
  freeTextBlurHandler() {
177
182
  queueMicrotask(() => {
@@ -195,6 +200,14 @@ class SiFilteredSearchInputComponent {
195
200
  this.searchValue.set('');
196
201
  }
197
202
  }
203
+ updateOverlayPositionAfterRender() {
204
+ afterNextRender(() => {
205
+ if (this.inputElement().nativeElement.matches(':focus')) {
206
+ this.inputElement().nativeElement.scrollIntoView({ block: 'nearest', inline: 'nearest' });
207
+ }
208
+ this.typeahead().updateOverlayPosition();
209
+ }, { injector: this.injector });
210
+ }
198
211
  requestCriterionByName(criterionMatch, editOnCreation) {
199
212
  let accepted = false;
200
213
  this.createCriterionByName.emit({
@@ -452,12 +465,13 @@ class SiFilteredSearchOptionValueBase extends SiFilteredSearchValueBase {
452
465
  if (initialValue.value?.length) {
453
466
  // Emit normalization after initialization, not during change detection.
454
467
  this.options()
455
- .pipe(take(1), observeOn(asapScheduler), takeUntilDestroyed(this.destroyRef))
456
- .subscribe(options => {
468
+ .pipe(take(1), map(options => this.criterionValue() === initialValue
469
+ ? this.processTypeaheadOptions(options)
470
+ : undefined), observeOn(asapScheduler), takeUntilDestroyed(this.destroyRef))
471
+ .subscribe(value => {
457
472
  if (this.criterionValue() !== initialValue) {
458
473
  return;
459
474
  }
460
- const value = this.processTypeaheadOptions(options);
461
475
  if (value !== undefined) {
462
476
  this.criterionValue.set({ ...initialValue, value });
463
477
  }