@@ -69,16 +69,6 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
6969 } )
7070 public showMax : number ;
7171
72- /**
73- * value determining if search is filtered to a group.
74- * @type {string }
75- */
76- @property ( {
77- attribute : 'group-id' ,
78- type : String
79- } )
80- public groupId : string ;
81-
8272 /**
8373 * array of user picked people.
8474 * @type {Array<IDynamicPerson> }
@@ -89,6 +79,23 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
8979 } )
9080 public selectedPeople : IDynamicPerson [ ] ;
9181
82+ /**
83+ * value determining if search is filtered to a group.
84+ * @type {string }
85+ */
86+ @property ( { attribute : 'group-id' } )
87+ public get groupId ( ) : string {
88+ return this . _groupId ;
89+ }
90+ public set groupId ( value ) {
91+ if ( this . _groupId === value ) {
92+ return ;
93+ }
94+
95+ this . _groupId = value ;
96+ this . requestStateUpdate ( true ) ;
97+ }
98+
9299 /**
93100 * User input in search.
94101 *
@@ -159,22 +166,6 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
159166 super . disconnectedCallback ( ) ;
160167 }
161168
162- /**
163- * Synchronizes property values when attributes change.
164- *
165- * @param {* } name
166- * @param {* } oldValue
167- * @param {* } newValue
168- * @memberof MgtPersonCard
169- */
170- public attributeChangedCallback ( att : string , oldval : string , newval : string ) {
171- super . attributeChangedCallback ( att , oldval , newval ) ;
172-
173- if ( att === 'group-id' && oldval !== newval ) {
174- this . requestStateUpdate ( ) ;
175- }
176- }
177-
178169 /**
179170 * Focuses the input element when focus is called
180171 *
@@ -250,6 +241,23 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
250241 ` ;
251242 }
252243
244+ /**
245+ * Request to reload the state.
246+ * Use reload instead of load to ensure loading events are fired.
247+ *
248+ * @protected
249+ * @memberof MgtBaseComponent
250+ */
251+ protected requestStateUpdate ( force ?: boolean ) {
252+ if ( force ) {
253+ this . _groupPeople = null ;
254+ this . people = null ;
255+ this . selectedPeople = [ ] ;
256+ }
257+
258+ return super . requestStateUpdate ( force ) ;
259+ }
260+
253261 /**
254262 * Render the input text box.
255263 *
@@ -474,26 +482,28 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
474482 return ;
475483 }
476484
477- if ( this . groupId !== this . _groupId ) {
478- this . _groupId = this . groupId ;
479- const graph = provider . graph . forComponent ( this ) ;
480- this . _groupPeople = await getPeopleFromGroup ( graph , this . groupId ) ;
481- }
482-
483- const query = this . userInput . toLowerCase ( ) ;
485+ const input = this . userInput . toLowerCase ( ) ;
484486 let people : IDynamicPerson [ ] ;
485487
486- // filtering groups
487488 if ( this . groupId ) {
488- people = this . _groupPeople ;
489- } else {
489+ if ( this . _groupPeople === null ) {
490+ try {
491+ const graph = provider . graph . forComponent ( this ) ;
492+ this . _groupPeople = await getPeopleFromGroup ( graph , this . groupId ) ;
493+ } catch {
494+ this . _groupPeople = [ ] ;
495+ }
496+ }
497+
498+ people = this . _groupPeople || [ ] ;
499+ } else if ( input ) {
490500 const graph = provider . graph . forComponent ( this ) ;
491- people = await findPerson ( graph , query ) ;
501+ people = await findPerson ( graph , input ) ;
492502 }
493503
494504 if ( people ) {
495505 people = people . filter ( ( person : IDynamicPerson ) => {
496- return person . displayName . toLowerCase ( ) . indexOf ( query ) !== - 1 ;
506+ return person . displayName . toLowerCase ( ) . indexOf ( input ) !== - 1 ;
497507 } ) ;
498508 }
499509
0 commit comments