@@ -606,6 +606,10 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
606606 this . addEventListener ( 'paste' , this . handlePaste ) ;
607607 }
608608
609+ private get hasMaxSelections ( ) : boolean {
610+ return this . selectionMode === 'single' && this . selectedPeople . length >= 1 ;
611+ }
612+
609613 /**
610614 * Focuses the input element when focus is called
611615 *
@@ -739,18 +743,8 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
739743 * @memberof MgtPeoplePicker
740744 */
741745 protected renderInput ( selectedPeopleTemplate : TemplateResult ) : TemplateResult {
742- const placeholder = ! this . disabled
743- ? this . placeholder
744- ? this . placeholder
745- : this . strings . inputPlaceholderText
746- : this . placeholder || '' ;
747-
748- const selectionMode = this . selectionMode ? this . selectionMode : 'multiple' ;
749-
750- if ( selectionMode === 'single' && this . selectedPeople . length >= 1 ) {
751- this . lostFocus ( ) ;
752- return html `` ;
753- }
746+ const placeholder = this . disabled ? '' : this . placeholder || this . strings . inputPlaceholderText ;
747+ const maxSelectionsAriaLabel = this . hasMaxSelections ? this . strings . maxSelectionsAriaLabel : '' ;
754748
755749 const searchIcon = html `<span class="search-icon">${ getSvg ( SvgIcon . Search ) } </span>` ;
756750 const startSlot = this . selectedPeople ?. length > 0 ? selectedPeopleTemplate : searchIcon ;
@@ -761,17 +755,17 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
761755 slot="anchor"
762756 id="people-picker-input"
763757 role="combobox"
758+ placeholder=${ this . hasMaxSelections ? this . strings . maxSelectionsPlaceHolder : placeholder }
759+ aria-label=${ this . ariaLabel || maxSelectionsAriaLabel || placeholder || this . strings . selectContact }
764760 aria-expanded=${ this . flyout ?. isOpen ?? false }
765- placeholder=${ placeholder }
766- aria-label=${ this . ariaLabel || placeholder || this . strings . selectContact }
767- @click="${ this . handleInputClick } "
768- @focus="${ this . gainedFocus } "
769- @keydown="${ this . onUserKeyDown } "
770- @keyup="${ this . onUserKeyUp } "
771- @input="${ this . onUserInput } "
761+ @click="${ this . hasMaxSelections ? undefined : this . handleInputClick } "
762+ @focus="${ this . hasMaxSelections ? undefined : this . gainedFocus } "
763+ @keydown="${ this . hasMaxSelections ? undefined : this . onUserKeyDown } "
764+ @input="${ this . hasMaxSelections ? undefined : this . onUserInput } "
772765 @blur="${ this . lostFocus } "
773- ?disabled=${ this . disabled } >
774- <span slot="start">${ startSlot } </span>
766+ ?disabled=${ this . disabled }
767+ >
768+ <span slot="start">${ startSlot } </span>
775769 </fluent-text-field>
776770 ` ;
777771 }
@@ -1296,10 +1290,14 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
12961290 }
12971291 return p . id !== person . id ;
12981292 } ) ;
1293+ const inputControl = this . input . shadowRoot . querySelector < HTMLInputElement > ( 'input' ) ;
1294+ if ( this . hasMaxSelections && inputControl ) {
1295+ inputControl . removeAttribute ( 'disabled' ) ;
1296+ }
12991297 this . selectedPeople = filteredPersonArr ;
13001298 void this . loadState ( ) ;
13011299 this . fireCustomEvent ( 'selectionChanged' , this . selectedPeople ) ;
1302- this . input ?. focus ( ) ;
1300+ inputControl ?. focus ( ) ;
13031301 }
13041302
13051303 /**
@@ -1473,6 +1471,11 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
14731471 // handle suggestion list item click
14741472 private handleSuggestionClick ( person : IDynamicPerson ) : void {
14751473 this . addPerson ( person ) ;
1474+ const inputControl = this . input . shadowRoot . querySelector < HTMLInputElement > ( 'input' ) ;
1475+ if ( this . hasMaxSelections && inputControl ) {
1476+ inputControl . setAttribute ( 'disabled' , 'true' ) ;
1477+ this . input . value = inputControl . value = '' ;
1478+ }
14761479 this . hideFlyout ( ) ;
14771480 }
14781481
@@ -1559,6 +1562,10 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
15591562 this . addPerson ( foundPerson ) ;
15601563 this . hideFlyout ( ) ;
15611564 this . input . value = '' ;
1565+ const inputControl = this . input . shadowRoot . querySelector < HTMLInputElement > ( 'input' ) ;
1566+ if ( this . hasMaxSelections && inputControl ) {
1567+ inputControl . setAttribute ( 'disabled' , 'true' ) ;
1568+ }
15621569 }
15631570 } else if ( this . allowAnyEmail ) {
15641571 this . handleAnyEmail ( ) ;
0 commit comments