From 020f4bac874532992c1127ad5dcb151034392136 Mon Sep 17 00:00:00 2001 From: yerramshilpa <44271677+yerramshilpa@users.noreply.github.com> Date: Wed, 7 Oct 2020 17:01:50 -0400 Subject: [PATCH] updated autocompltet (#521) --- package.json | 2 +- .../autocomplete-search.component.ts | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 29aa4742d..bdf54b2d2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gsa-sam/sam-ui-elements", - "version": "1.0.14", + "version": "1.0.16", "description": "SAM UI library", "repository": { "type": "git", diff --git a/src/ui-kit/form-controls/sam-sds-autocomplete/autocomplete-search/autocomplete-search.component.ts b/src/ui-kit/form-controls/sam-sds-autocomplete/autocomplete-search/autocomplete-search.component.ts index 4fb04ec4d..625e9dcdd 100755 --- a/src/ui-kit/form-controls/sam-sds-autocomplete/autocomplete-search/autocomplete-search.component.ts +++ b/src/ui-kit/form-controls/sam-sds-autocomplete/autocomplete-search/autocomplete-search.component.ts @@ -133,6 +133,9 @@ export class SAMSDSAutocompleteSearchComponent implements ControlValueAccessor { */ @Input() public inputReadOnly = false; + public isItemSelected: boolean = false; + + /** * Stored Event for ControlValueAccessor */ @@ -234,9 +237,19 @@ export class SAMSDSAutocompleteSearchComponent implements ControlValueAccessor { if (this.configuration.selectionMode === SelectionMode.SINGLE) { const val = this.inputValue; if (this.configuration.isTagModeEnabled || this.configuration.isFreeTextEnabled) { - SAMSDSSelectedItemModelHelper.clearItems(this.model); - this.propogateChange(this.model); - this.selectItem(this.createFreeTextItem(val)); + if ( + SAMSDSSelectedItemModelHelper.containsItem( + val, + this.configuration.primaryKeyField, + this.model.items + ) + ) { + SAMSDSSelectedItemModelHelper.clearItems(this.model); + this.propogateChange(this.model); + this.selectItem(this.createFreeTextItem(val)); + } else { + this.selectItem(this.createFreeTextItem(val)); + } } } else if ( this.configuration.selectionMode === SelectionMode.MULTIPLE @@ -374,6 +387,7 @@ export class SAMSDSAutocompleteSearchComponent implements ControlValueAccessor { * @param item */ public selectItem(item: object): void { + this.isItemSelected = true; let filterItem = {}; if (this.essentialModelFields) { filterItem[this.configuration.primaryKeyField] = @@ -449,7 +463,7 @@ export class SAMSDSAutocompleteSearchComponent implements ControlValueAccessor { if (selectedChild) { selectedChild.scrollIntoView({ behavior: "smooth", - block: "center", + block: "nearest", inline: "start", }); }