From 55596828946b2f76ae2726fc58b90d2bcc57000d Mon Sep 17 00:00:00 2001 From: Thomas Pourchel Date: Fri, 2 Feb 2024 16:28:23 +0100 Subject: [PATCH] autocomplete modifs --- .../autocomplete/autocomplete.component.css | 10 ++++--- .../autocomplete/autocomplete.component.html | 27 ++++++------------- .../autocomplete/autocomplete.component.ts | 22 ++++++++++----- .../autocomplete-page.component.html | 2 +- .../autocomplete-page.component.ts | 2 +- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.css b/projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.css index bf14aa1..cc10bb2 100644 --- a/projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.css +++ b/projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.css @@ -1,10 +1,10 @@ #b1-listbox { - padding: 0.4rem; position: absolute; list-style: none; background-color: white; border: 1px solid grey; - min-width: 14.6rem; + min-width: 13rem; + max-width: 13rem; max-height: 14rem; overflow: scroll; overflow-x: hidden; @@ -13,6 +13,10 @@ } #b1-listbox li { - padding: 10px; + padding: 0.5rem; +} + +#b1-listbox li:hover { + background-color: grey; } diff --git a/projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.html b/projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.html index 4c12c2d..19ae10d 100644 --- a/projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.html +++ b/projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.html @@ -1,5 +1,5 @@ -
+
- -
    -

    -

  • {{ li }}
  • -

    +
      +
    • + {{ li }} +
diff --git a/projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.ts b/projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.ts index c63c017..c3f3965 100644 --- a/projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.ts +++ b/projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.ts @@ -1,4 +1,4 @@ -import { Component, Input } from '@angular/core'; +import { Component, ElementRef, Input, ViewChild } from '@angular/core'; @Component({ selector: 'c3m-autocomplete', @@ -8,17 +8,21 @@ import { Component, Input } from '@angular/core'; export class AutocompleteComponent { @Input() isOpen = false; @Input() label = ''; - @Input() countries: Array = []; + @Input() values: Array = []; @Input() acValue = ''; - @Input() filteredCountriesList: Array = []; + @Input() filteredList: Array = []; + @Input() selectedValue = false; + @ViewChild('acInput') acInput!: ElementRef; - toggleOpen(): void { + open(): void { this.isOpen = !this.isOpen; this.onChange; } close(): void { - this.isOpen = false; + setTimeout(() => { + this.isOpen = false; + }, 300); } escClose(event: KeyboardEvent): void { @@ -29,6 +33,12 @@ export class AutocompleteComponent { onChange(e: any) { this.acValue = e.target.value; - this.filteredCountriesList = this.countries.filter(country => country.toLowerCase().startsWith(this.acValue.toLowerCase())); + this.filteredList = this.values.filter(value => value.toLowerCase().startsWith(this.acValue.toLowerCase())); + } + + getSelectedValue(val: string) { + this.acInput.nativeElement.value = val; + this.selectedValue = true; + this.close(); } } diff --git a/src/app/pages/autocomplete-page/autocomplete-page.component.html b/src/app/pages/autocomplete-page/autocomplete-page.component.html index 83ecb62..80479cf 100644 --- a/src/app/pages/autocomplete-page/autocomplete-page.component.html +++ b/src/app/pages/autocomplete-page/autocomplete-page.component.html @@ -3,7 +3,7 @@

Autocomplete

- +

diff --git a/src/app/pages/autocomplete-page/autocomplete-page.component.ts b/src/app/pages/autocomplete-page/autocomplete-page.component.ts
index 4950659..13f031f 100644
--- a/src/app/pages/autocomplete-page/autocomplete-page.component.ts
+++ b/src/app/pages/autocomplete-page/autocomplete-page.component.ts
@@ -10,7 +10,7 @@ export class AutocompletePageComponent {
   componentName = 'c3m-autocomplete';
   resourceType = 'Component';
 
-  countries = [
+  values = [
     'Hauts-de-France',
     'Normandie',
     'Grand Est',