@@ -103,6 +103,13 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
103103 return styles ;
104104 }
105105
106+ /**
107+ * The strings to be used for localizing the component.
108+ *
109+ * @readonly
110+ * @protected
111+ * @memberof MgtPeoplePicker
112+ */
106113 protected get strings ( ) {
107114 return strings ;
108115 }
@@ -241,7 +248,7 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
241248 }
242249
243250 /**
244- * User type to search for.
251+ * The type of user to search for. Default is any .
245252 *
246253 * @readonly
247254 * @type {UserType }
@@ -275,7 +282,15 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
275282 attribute : 'transitive-search' ,
276283 type : Boolean
277284 } )
278- public transitiveSearch : boolean ;
285+ public get transitiveSearch ( ) : boolean {
286+ return this . _transitiveSearch ;
287+ }
288+ public set transitiveSearch ( value : boolean ) {
289+ if ( this . transitiveSearch !== value ) {
290+ this . _transitiveSearch = value ;
291+ this . requestStateUpdate ( true ) ;
292+ }
293+ }
279294
280295 /**
281296 * containing object of IDynamicPerson.
@@ -285,7 +300,15 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
285300 attribute : 'people' ,
286301 type : Object
287302 } )
288- public people : IDynamicPerson [ ] ;
303+ public get people ( ) : IDynamicPerson [ ] {
304+ return this . _people ;
305+ }
306+ public set people ( value : IDynamicPerson [ ] ) {
307+ if ( ! arraysAreEqual ( this . _people , value ) ) {
308+ this . _people = value ;
309+ this . requestStateUpdate ( true ) ;
310+ }
311+ }
289312
290313 /**
291314 * determining how many people to show in list.
@@ -295,7 +318,15 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
295318 attribute : 'show-max' ,
296319 type : Number
297320 } )
298- public showMax : number ;
321+ public get showMax ( ) : number {
322+ return this . _showMax ;
323+ }
324+ public set showMax ( value : number ) {
325+ if ( value !== this . _showMax ) {
326+ this . _showMax = value ;
327+ this . requestStateUpdate ( true ) ;
328+ }
329+ }
299330
300331 /**
301332 * Sets whether the person image should be fetched
@@ -311,17 +342,25 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
311342 public disableImages : boolean ;
312343
313344 /**
314- * array of user picked people.
345+ * array of user picked people.
315346 * @type {IDynamicPerson[] }
316347 */
317348 @property ( {
318349 attribute : 'selected-people' ,
319350 type : Array
320351 } )
321- public selectedPeople : IDynamicPerson [ ] ;
352+ public get selectedPeople ( ) : IDynamicPerson [ ] {
353+ return this . _selectedPeople ;
354+ }
355+ public set selectedPeople ( value : IDynamicPerson [ ] ) {
356+ if ( ! value ) value = [ ] ;
357+ if ( ! arraysAreEqual ( this . _selectedPeople , value ) ) {
358+ this . _selectedPeople = value ;
359+ }
360+ }
322361
323362 /**
324- * array of people to be selected upon intialization
363+ * array of people to be selected upon initialization
325364 *
326365 * @type {string[] }
327366 * @memberof MgtPeoplePicker
@@ -333,10 +372,18 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
333372 } ,
334373 type : String
335374 } )
336- public defaultSelectedUserIds : string [ ] ;
375+ public get defaultSelectedUserIds ( ) : string [ ] {
376+ return this . _defaultSelectedUserIds ;
377+ }
378+ public set defaultSelectedUserIds ( value ) {
379+ if ( ! arraysAreEqual ( this . _defaultSelectedUserIds , value ) ) {
380+ this . _defaultSelectedUserIds = value ;
381+ this . requestStateUpdate ( true ) ;
382+ }
383+ }
337384
338385 /**
339- * array of groups to be selected upon intialization
386+ * array of groups to be selected upon initialization
340387 *
341388 * @type {string[] }
342389 * @memberof MgtPeoplePicker
@@ -348,7 +395,15 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
348395 } ,
349396 type : String
350397 } )
351- public defaultSelectedGroupIds : string [ ] ;
398+ public get defaultSelectedGroupIds ( ) : string [ ] {
399+ return this . _defaultSelectedGroupIds ;
400+ }
401+ public set defaultSelectedGroupIds ( value ) {
402+ if ( ! arraysAreEqual ( this . _defaultSelectedGroupIds , value ) ) {
403+ this . _defaultSelectedGroupIds = value ;
404+ this . requestStateUpdate ( true ) ;
405+ }
406+ }
352407
353408 /**
354409 * Placeholder text.
@@ -398,7 +453,6 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
398453 } )
399454 public selectionMode : string ;
400455
401- private _userIds : string [ ] ;
402456 /**
403457 * Array of the only users to be searched.
404458 *
@@ -495,8 +549,9 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
495549 protected userInput : string ;
496550
497551 // if search is still loading don't load "people not found" state
498- @property ( { attribute : false } ) private _showLoading : boolean ;
552+ @state ( ) private _showLoading : boolean ;
499553
554+ private _userIds : string [ ] ;
500555 private _groupId : string ;
501556 private _groupIds : string [ ] ;
502557 private _type : PersonType = PersonType . person ;
@@ -505,6 +560,13 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
505560 private _userFilters : string ;
506561 private _groupFilters : string ;
507562 private _peopleFilters : string ;
563+ private _defaultSelectedGroupIds : string [ ] ;
564+ private _defaultSelectedUserIds : string [ ] ;
565+ private _selectedPeople : IDynamicPerson [ ] = [ ] ;
566+ private _showMax : number ;
567+ private _people : IDynamicPerson [ ] ;
568+ private _transitiveSearch : boolean ;
569+
508570 private defaultPeople : IDynamicPerson [ ] ;
509571
510572 // tracking of user arrow key input for selection
@@ -688,7 +750,7 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
688750 * @memberof MgtPeoplePicker
689751 */
690752 protected renderInput ( ) : TemplateResult {
691- const hasSelectedPeople = ! ! this . selectedPeople . length ;
753+ const hasSelectedPeople = this . selectedPeople ? .length > 0 ;
692754
693755 const placeholder = ! this . disabled
694756 ? this . placeholder
@@ -729,6 +791,7 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
729791 @focus="${ this . gainedFocus } "
730792 @keydown="${ this . onUserKeyDown } "
731793 @keyup="${ this . onUserKeyUp } "
794+ @input="${ this . onUserInput } "
732795 @blur=${ this . lostFocus }
733796 ?disabled=${ this . disabled }
734797 />
@@ -1071,7 +1134,7 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
10711134 }
10721135
10731136 if (
1074- ( this . defaultSelectedUserIds || this . defaultSelectedGroupIds ) &&
1137+ ( this . defaultSelectedUserIds ?. length > 0 || this . defaultSelectedGroupIds ?. length > 0 ) &&
10751138 ! this . selectedPeople . length &&
10761139 ! this . defaultSelectedUsers
10771140 ) {
@@ -1168,7 +1231,7 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
11681231 }
11691232 }
11701233 } catch ( e ) {
1171- // nop
1234+ // no-op
11721235 }
11731236 }
11741237 }
@@ -1184,7 +1247,9 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
11841247 this . groupType ,
11851248 this . userFilters
11861249 ) ;
1187- } catch ( _ ) { }
1250+ } catch ( _ ) {
1251+ // no-op
1252+ }
11881253 } else {
11891254 let groups = [ ] ;
11901255 try {
@@ -1269,7 +1334,7 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
12691334 this . fireCustomEvent ( 'selectionChanged' , this . selectedPeople ) ;
12701335 if ( this . selectedPeople . length <= 0 ) this . showSearchIcon ( ) ;
12711336
1272- this . input . focus ( ) ;
1337+ this . input ? .focus ( ) ;
12731338 }
12741339
12751340 /**
@@ -1365,7 +1430,6 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
13651430 const isPaste = ( event . ctrlKey || event . metaKey ) && event . key === 'v' ;
13661431 const isCmdOrCtrlKey = [ 'ControlLeft' , 'ControlRight' ] . includes ( event . code ) || event . ctrlKey || event . metaKey ;
13671432 const isArrowKey = [ 'ArrowDown' , 'ArrowRight' , 'ArrowUp' , 'ArrowLeft' ] . includes ( event . code ) ;
1368- const input = event . target as HTMLInputElement ;
13691433
13701434 if ( ( ! isPaste && isCmdOrCtrlKey ) || isArrowKey ) {
13711435 if ( isCmdOrCtrlKey || [ 'ArrowLeft' , 'ArrowRight' ] . includes ( event . code ) ) {
@@ -1426,17 +1490,22 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
14261490 }
14271491 return ;
14281492 }
1493+ }
14291494
1495+ private onUserInput ( event : InputEvent ) {
1496+ const input = event . target as HTMLInputElement ;
14301497 this . userInput = input . value ;
1431- const validEmail = isValidEmail ( this . userInput ) ;
1432- if ( validEmail && this . allowAnyEmail ) {
1433- if ( this . _setAnyEmail ) {
1434- this . handleAnyEmail ( ) ;
1498+ if ( this . userInput ) {
1499+ const validEmail = isValidEmail ( this . userInput ) ;
1500+ if ( validEmail && this . allowAnyEmail ) {
1501+ if ( this . _setAnyEmail ) {
1502+ this . handleAnyEmail ( ) ;
1503+ }
1504+ } else {
1505+ this . handleUserSearch ( ) ;
14351506 }
1436- } else {
1437- this . handleUserSearch ( ) ;
1507+ this . _setAnyEmail = false ;
14381508 }
1439- this . _setAnyEmail = false ;
14401509 }
14411510
14421511 private handleAnyEmail ( ) {
0 commit comments