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.spec.ts b/projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.spec.ts index c8df2b8..ff57505 100644 --- a/projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.spec.ts +++ b/projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.spec.ts @@ -8,9 +8,8 @@ describe('AutocompleteComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [ AutocompleteComponent ] - }) - .compileComponents(); + declarations: [AutocompleteComponent], + }).compileComponents(); fixture = TestBed.createComponent(AutocompleteComponent); component = fixture.componentInstance; 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..5ed5378 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,24 @@ 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; + if (this.selectedValue == false) { + // vérifier si acInput est vide pour que la scrollbar fonctionne + this.isOpen = true; + } else { + this.isOpen = false; + } } escClose(event: KeyboardEvent): void { @@ -27,8 +34,39 @@ export class AutocompleteComponent { } } + navigationKeyDown(val: string) { + if (this.isOpen == true && this.selectedValue == true) { + //déplace le focus visuel vers la valeur suggérée suivante + } + + this.acInput.nativeElement.value = val; + if (val == '' && this.isOpen == false) { + // déplace le focus visuel sur la première option + } + } + + navigationKeyUp(val: string) { + if (this.isOpen == true && this.selectedValue == true) { + //déplace le focus visuel sur la dernière valeur suggérée + } + + this.acInput.nativeElement.value = val; + if (val == '') { + if (this.isOpen == false) { + this.isOpen = true; + } + // déplace le focus visuel sur la dernière option + } + } + 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',