@@ -51,9 +51,10 @@ export class BillingAccountFormComponent implements OnInit, OnDestroy {
5151 telephoneNumber : new FormControl ( '' , [ Validators . required , Validators . min ( 0 ) ] ) ,
5252 telephoneType : new FormControl ( 'Mobile' )
5353 } ) ;
54- prefixes : any [ ] = phoneNumbers ;
54+ prefixes : any [ ] = [ ... phoneNumbers ] . sort ( ( a , b ) => this . getCountryName ( a . text ) . localeCompare ( this . getCountryName ( b . text ) ) ) ;
5555 countries : any [ ] = countries ;
5656 phonePrefix : any = phoneNumbers [ 0 ] ;
57+ @ViewChild ( 'prefixList' ) prefixListRef ! : ElementRef ;
5758 prefixCheck : boolean = false ;
5859 toastVisibility : boolean = false ;
5960
@@ -404,6 +405,22 @@ export class BillingAccountFormComponent implements OnInit, OnDestroy {
404405 }
405406 }
406407
408+ getCountryName ( text : string ) : string {
409+ const match = text . match ( / \+ \d + \s + ( .+ ) $ / ) ;
410+ return match ? match [ 1 ] : text ;
411+ }
412+
413+ @HostListener ( 'keydown' , [ '$event' ] )
414+ onKeydown ( event : KeyboardEvent ) {
415+ if ( ! this . prefixCheck ) return ;
416+ const letter = event . key . toLowerCase ( ) ;
417+ if ( ! / ^ [ a - z ] $ / . test ( letter ) ) return ;
418+ const match = this . prefixes . find ( p => this . getCountryName ( p . text ) . toLowerCase ( ) . startsWith ( letter ) ) ;
419+ if ( ! match || ! this . prefixListRef ) return ;
420+ const btn = this . prefixListRef . nativeElement . querySelector ( `[data-country="${ match . country } "]` ) ;
421+ if ( btn ) btn . scrollIntoView ( { block : 'nearest' } ) ;
422+ }
423+
407424 selectPrefix ( pref :any ) {
408425 console . log ( pref )
409426 this . prefixCheck = false ;
0 commit comments