Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply keyboard focus when removing selected person or adding person from suggestion list on people-picker #3011

Merged
merged 8 commits into from
Feb 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,8 @@ export class MgtPeoplePicker extends MgtTemplatedTaskComponent {
id="${person.id}"
class="searched-people-list-result"
role="option"
@click="${() => this.handleSuggestionClick(person)}">
@click="${() => this.handleSuggestionClick(person)}"
@keydown="${(e: KeyboardEvent) => this.handleSuggestionKeydown(person, e)}">
Mnickii marked this conversation as resolved.
Show resolved Hide resolved
${this.renderPersonResult(person)}
</li>
`
Expand Down Expand Up @@ -1200,9 +1201,6 @@ export class MgtPeoplePicker extends MgtTemplatedTaskComponent {
}
return p.id !== person.id;
});
if (this.hasMaxSelections) {
this.enableTextInput();
}
this.selectedPeople = filteredPersonArr;
void this.loadState();
}
Expand All @@ -1216,6 +1214,7 @@ export class MgtPeoplePicker extends MgtTemplatedTaskComponent {
protected handleRemovePersonKeyDown(person: IDynamicPerson, e: KeyboardEvent): void {
if (e.key === 'Enter') {
this.removePerson(person, e);
this.enableTextInput();
Mnickii marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -1243,6 +1242,7 @@ export class MgtPeoplePicker extends MgtTemplatedTaskComponent {
this._foundPeople = [];
this._arrowSelectionCount = -1;
}
this.enableTextInput();
}
}

Expand Down Expand Up @@ -1381,6 +1381,18 @@ export class MgtPeoplePicker extends MgtTemplatedTaskComponent {
this.hideFlyout();
}

// handle suggestion list item keydown
private handleSuggestionKeydown(person: IDynamicPerson, e: KeyboardEvent): void {
if (e.key === 'Enter') {
this.addPerson(person);
if (this.hasMaxSelections) {
this.disableTextInput();
this.input.value = '';
}
this.hideFlyout();
}
}

/**
* Tracks event on user input in search
*
Expand Down
Loading