@@ -13,13 +13,18 @@ import { getPeople, getPeopleFromResource } from '../../graph/graph.people';
1313import { getUsersPresenceByPeople } from '../../graph/graph.presence' ;
1414import { findGroupMembers , getUsersForPeopleQueries , getUsersForUserIds } from '../../graph/graph.user' ;
1515import { IDynamicPerson } from '../../graph/types' ;
16- import { Providers , ProviderState , MgtTemplatedTaskComponent , mgtHtml } from '@microsoft/mgt-element' ;
16+ import {
17+ Providers ,
18+ ProviderState ,
19+ MgtTemplatedTaskComponent ,
20+ registerComponent ,
21+ mgtHtml
22+ } from '@microsoft/mgt-element' ;
1723import '../../styles/style-helper' ;
1824import { type PersonCardInteraction , personCardConverter } from './../PersonCardInteraction' ;
1925
2026import { styles } from './mgt-people-css' ;
2127import { MgtPerson , registerMgtPersonComponent } from '../mgt-person/mgt-person' ;
22- import { registerComponent } from '@microsoft/mgt-element' ;
2328
2429/**
2530 * web component to display a group of people or contacts by using their photos or initials.
@@ -249,6 +254,19 @@ export class MgtPeople extends MgtTemplatedTaskComponent {
249254 return this . renderTemplate ( 'default' , { people : this . people , max : this . showMax } ) || this . renderPeople ( ) ;
250255 } ;
251256
257+ protected updated ( changedProperties : Map < string | number | symbol , unknown > ) : void {
258+ super . updated ( changedProperties ) ;
259+ this . checkPeopleListAndFireEvent ( ) ;
260+ }
261+
262+ private checkPeopleListAndFireEvent ( ) : void {
263+ const peopleList = this . shadowRoot ?. querySelector ( '.people-list' ) ;
264+
265+ if ( peopleList ?. childElementCount > 0 ) {
266+ this . fireCustomEvent ( 'people-rendered' ) ;
267+ }
268+ }
269+
252270 /**
253271 * Render the loading state.
254272 *
@@ -280,7 +298,7 @@ export class MgtPeople extends MgtTemplatedTaskComponent {
280298 maxPeople ,
281299 p => ( p . id ? p . id : p . displayName ) ,
282300 p => html `
283- <li tabindex="-1" class="people-person">
301+ <li class="people-person">
284302 ${ this . renderPerson ( p ) }
285303 </li>
286304 `
@@ -306,7 +324,7 @@ export class MgtPeople extends MgtTemplatedTaskComponent {
306324 people : this . people
307325 } ) ||
308326 html `
309- <li tabindex="-1" aria-label="and ${ extra } more attendees" class="overflow"><span>+${ extra } </span></li>
327+ <li aria-label="and ${ extra } more attendees" class="overflow"><span>+${ extra } </span></li>
310328 `
311329 ) ;
312330 }
@@ -320,22 +338,33 @@ export class MgtPeople extends MgtTemplatedTaskComponent {
320338 const peopleContainer : HTMLElement = this . shadowRoot . querySelector ( '.people-list' ) ;
321339 let person : HTMLElement ;
322340 const peopleElements : HTMLCollection = peopleContainer ?. children ;
341+ const keyName = event . key ;
323342 // Default all tabindex values in li nodes to -1
324343 for ( const element of peopleElements ) {
325344 const el : HTMLElement = element as HTMLElement ;
326- el . setAttribute ( 'tabindex' , '-1' ) ;
345+ el . removeAttribute ( 'tabindex' ) ;
346+ person = el ?. querySelector ( 'mgt-person' ) ;
347+ person = person ?. shadowRoot . querySelector ( '.person-root' ) ;
348+ person ?. removeAttribute ( 'tabindex' ) ;
327349 el . blur ( ) ;
328350 }
351+ if ( event . target === peopleContainer && ( keyName === 'Tab' || keyName === 'Escape' ) ) {
352+ this . _arrowKeyLocation = - 1 ;
353+ peopleContainer ?. blur ( ) ;
354+ }
329355
330- const childElementCount = peopleContainer . childElementCount ;
331- const keyName = event . key ;
356+ let childElementCount = peopleContainer ?. childElementCount ;
357+ let overflow = peopleContainer ?. querySelector ( '.overflow' ) ;
358+ if ( overflow ) {
359+ // account for overflow
360+ overflow = overflow as HTMLElement ;
361+ overflow . removeAttribute ( 'tabindex' ) ;
362+ childElementCount -- ;
363+ }
332364 if ( keyName === 'ArrowRight' ) {
333365 this . _arrowKeyLocation = ( this . _arrowKeyLocation + 1 + childElementCount ) % childElementCount ;
334366 } else if ( keyName === 'ArrowLeft' ) {
335367 this . _arrowKeyLocation = ( this . _arrowKeyLocation - 1 + childElementCount ) % childElementCount ;
336- } else if ( keyName === 'Tab' || keyName === 'Escape' ) {
337- this . _arrowKeyLocation = - 1 ;
338- peopleContainer . blur ( ) ;
339368 } else if ( [ 'Enter' , 'space' , ' ' ] . includes ( keyName ) ) {
340369 if ( this . personCardInteraction !== 'none' ) {
341370 const personEl = peopleElements [ this . _arrowKeyLocation ] as HTMLElement ;
@@ -348,8 +377,10 @@ export class MgtPeople extends MgtTemplatedTaskComponent {
348377
349378 if ( this . _arrowKeyLocation > - 1 ) {
350379 person = peopleElements [ this . _arrowKeyLocation ] as HTMLElement ;
351- person . setAttribute ( 'tabindex' , '1 ' ) ;
380+ person . setAttribute ( 'tabindex' , '0 ' ) ;
352381 person . focus ( ) ;
382+ person = person . querySelector ( '.people-person' ) ;
383+ person ?. shadowRoot . querySelector ( '.person-root' ) . setAttribute ( 'tabindex' , '0' ) ;
353384 }
354385 } ;
355386
@@ -377,7 +408,6 @@ export class MgtPeople extends MgtTemplatedTaskComponent {
377408 // query the image from the graph
378409 mgtHtml `
379410 <mgt-person
380- class="people-person"
381411 .personDetails=${ person }
382412 .fetchImage=${ true }
383413 .avatarSize=${ avatarSize }
0 commit comments