Skip to content

PeoplePicker: defaultSelectedUsers resolves wrong group when groups have similar names #2101

@c-eiser13

Description

@c-eiser13

Category

[ ] Enhancement

[ X] Bug

[ ] Question

Version

Please specify what version of the library you are using: [ 3.25.0 ]

If you are not using the latest release, please update and see if the issue is resolved before submitting an issue.

Expected / Desired Behavior / Question

When people picker is used in a controlled way, for example in a new/edit form, defaultSelectedUsers should resolve the correct group.

Observed Behavior

When using defaultSelectedUsers and passing a group that has similar named group, the wrong group name is resolved. For example, I have 2 security groups, Communications and Communications Manager. If I set defaultSelectedUsers to the Communications group, when the component loads, Communication Manager is what is resolved.

Image Image

Also, if I have defaultSelectedUsers pointed to a state variable, in an edit form expereince, for example, if I type Communications into the people picker and select it, defaultSelectedUsers is also called since there was a state update, and resolves it to the incorrect Communications Manager group.

I've traced this to the searchPersonByEmailOrLogin function in PeopleSearchService, which is hard-coded to only return 1 result, which works fine with email addresses or login names, but when dealing with security groups, we can only use the group name (as far as I can tell).

Image

Using same exmaple, defaultSelectedUsers=["Communications"], this is what happens:

Communications is the query
Image

But the 1 result that is resolved is Communications Manager

Image

I am able to resolve this issue for both groups and users by increasing the max suggestions from 1 to a higher number. Currently, I am optionally using the maximumSuggestions prop and defaulting to 5 at a minimum. Open to suggestions on best way to configure that value, but doing this alleviates this issue:

Image

Same Communications value passed in

Image

Now I get both Communications and Communications Manager groups

Image

The userResult[0], in all of my groups testing contains the correct group.

Image

A better approach would be to filter this array based on the value that was passed in to ensure you get the proper result.

Image

I will submit a PR and can help make any proposed tweaks, but in my testing this approach has corrected the issue.

Steps to Reproduce

This can be tricky, the communications example above is present in my client's tenant, but if I create those two named groups in my tenant, it does not present. However, in my tenant, I have two groups, "English Test Group" and "English Test Group2" which repros the issue; when defaulting "English Test Group" the other group "English Test Group2" resolves when defaultSelectedUsers is called.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions