@@ -572,7 +572,8 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
572572 private defaultPeople : IDynamicPerson [ ] ;
573573
574574 // tracking of user arrow key input for selection
575- private _arrowSelectionCount : number = - 1 ;
575+ @state ( ) private _arrowSelectionCount = - 1 ;
576+
576577 // List of people requested if group property is provided
577578 private _groupPeople : IDynamicPerson [ ] ;
578579 private _debouncedSearch : { ( ) : void ; ( ) : void } ;
@@ -852,13 +853,18 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
852853 */
853854 protected renderFlyout ( anchor : TemplateResult ) : TemplateResult {
854855 return html `
855- < mgt-flyout light-dismiss class ="flyout ">
856- ${ anchor }
857- < div slot ="flyout " class ="flyout-root " @wheel =${ ( e : WheelEvent ) => this . handleSectionScroll ( e ) } >
858- ${ this . renderFlyoutContent ( ) }
859- </ div >
860- </ mgt-flyout >
861- ` ;
856+ < mgt-flyout light-dismiss class ="flyout ">
857+ ${ anchor }
858+ < div
859+ slot ="flyout "
860+ class ="flyout-root "
861+ @wheel =${ ( e : WheelEvent ) => this . handleSectionScroll ( e ) }
862+ @keydown =${ ( e : KeyboardEvent ) => this . onUserKeyDown ( e ) }
863+ >
864+ ${ this . renderFlyoutContent ( ) }
865+ </ div >
866+ </ mgt-flyout >
867+ ` ;
862868 }
863869
864870 /**
@@ -937,7 +943,6 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
937943 */
938944 protected renderSearchResults ( people : IDynamicPerson [ ] ) {
939945 const filteredPeople = people . filter ( person => person . id ) ;
940-
941946 return html `
942947 < ul
943948 id ="suggestions-list "
@@ -950,14 +955,16 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
950955 filteredPeople ,
951956 person => person . id ,
952957 person => {
958+ const lineTwo = person . jobTitle || ( person as User ) . mail ;
959+ const ariaLabel = `${ this . strings . suggestedContact } ${ person . displayName } ${ lineTwo ?? '' } ` ;
953960 return html `
954961 < li
955962 id ="${ person . id } "
956- aria-label =" ${ this . strings . suggestedContact } ${ person . displayName } "
963+ aria-label ="${ ariaLabel } "
957964 class ="list-person "
958965 role ="option "
959966 @click ="${ e => this . handleSuggestionClick ( person ) } ">
960- ${ this . renderPersonResult ( person ) }
967+ ${ this . renderPersonResult ( person ) }
961968 </ li >
962969 ` ;
963970 }
@@ -1309,6 +1316,7 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
13091316 if ( this . input ) {
13101317 this . input . setAttribute ( 'aria-expanded' , 'true' ) ;
13111318 }
1319+ this . _arrowSelectionCount = - 1 ;
13121320 }
13131321
13141322 /**
@@ -1387,13 +1395,13 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
13871395 private gainedFocus ( ) {
13881396 this . clearHighlighted ( ) ;
13891397 this . _isFocused = true ;
1390- this . loadState ( ) ;
1398+ void this . loadState ( ) ;
1399+ this . showFlyout ( ) ;
13911400 }
13921401
13931402 // handle input blur
13941403 private lostFocus ( ) {
13951404 this . _isFocused = false ;
1396- this . _arrowSelectionCount = - 1 ;
13971405 if ( this . input ) {
13981406 this . input . setAttribute ( 'aria-expanded' , 'false' ) ;
13991407 this . input . setAttribute ( 'aria-activedescendant' , '' ) ;
@@ -1402,9 +1410,9 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
14021410 const peopleList = this . renderRoot . querySelector ( '.people-list' ) ;
14031411
14041412 if ( peopleList ) {
1405- for ( let i = 0 ; i < peopleList . children . length ; i ++ ) {
1406- peopleList . children [ i ] . classList . remove ( 'focused' ) ;
1407- peopleList . children [ i ] . setAttribute ( 'aria-selected' , 'false' ) ;
1413+ for ( const el of peopleList . children ) {
1414+ el . classList . remove ( 'focused' ) ;
1415+ el . setAttribute ( 'aria-selected' , 'false' ) ;
14081416 }
14091417 }
14101418
@@ -1626,9 +1634,8 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
16261634
16271635 if ( event . key === 'ArrowUp' || event . key === 'ArrowDown' ) {
16281636 this . handleArrowSelection ( event ) ;
1629- if ( input . value . length > 0 ) {
1630- event . preventDefault ( ) ;
1631- }
1637+ // prevent page from scrolling
1638+ event . preventDefault ( ) ;
16321639 }
16331640
16341641 if ( event . code === 'Enter' ) {
@@ -1862,28 +1869,31 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
18621869 if ( this . _arrowSelectionCount === - 1 ) {
18631870 this . _arrowSelectionCount = 0 ;
18641871 } else {
1865- this . _arrowSelectionCount = ( this . _arrowSelectionCount + 1 ) % peopleList . children . length ;
1872+ this . _arrowSelectionCount =
1873+ ( this . _arrowSelectionCount + 1 + peopleList . children . length ) % peopleList . children . length ;
18661874 }
18671875 }
18681876 }
18691877
18701878 // reset background color
18711879 // reset aria-selected to false
1872- // tslint:disable-next-line: prefer-for-of
1873- for ( let i = 0 ; i < peopleList . children . length ; i ++ ) {
1874- peopleList . children [ i ] . classList . remove ( 'focused' ) ;
1875- peopleList . children [ i ] . setAttribute ( 'aria-selected' , 'false' ) ;
1880+ for ( const person of peopleList ?. children ) {
1881+ const p = person as HTMLElement ;
1882+ p . setAttribute ( 'aria-selected' , 'false' ) ;
1883+ p . removeAttribute ( 'tabindex' ) ;
1884+ p . blur ( ) ;
18761885 }
18771886
18781887 // set selected background
18791888 // set aria-selected to true
18801889 const focusedItem = peopleList . children [ this . _arrowSelectionCount ] as HTMLElement ;
18811890
18821891 if ( focusedItem ) {
1883- focusedItem . classList . add ( 'focused' ) ;
1892+ focusedItem . setAttribute ( 'tabindex' , '0' ) ;
1893+ focusedItem . focus ( ) ;
18841894 focusedItem . scrollIntoView ( { behavior : 'smooth' , block : 'nearest' , inline : 'nearest' } ) ;
18851895 focusedItem . setAttribute ( 'aria-selected' , 'true' ) ;
1886- this . input . setAttribute ( 'aria-activedescendant' , peopleList . children [ this . _arrowSelectionCount ] . id ) ;
1896+ this . input . setAttribute ( 'aria-activedescendant' , focusedItem . id ) ;
18871897 }
18881898 }
18891899 }
0 commit comments