microsoft-graph-toolkit icon indicating copy to clipboard operation
microsoft-graph-toolkit copied to clipboard

People picker: selectUsersById causes user dropdown to open up

Open web265p3 opened this issue 1 year ago • 5 comments

Describe the bug Whenever I use the function selectUserById of the people picker component, the dropdown to pick a user opens up.

To Reproduce Steps to reproduce the behavior:

  1. Create the people picker component. ie:

<mgt-people-picker ngDefaultControl name="people" id="MY_TEST_ID"> </mgt-people-picker> 2. Call the selectUserById function:

(document.getElementById('MY_TEST_ID') as any).selectUsersById(['977c3cbe-e47e-xxxx-b92c-0739ad67ebbe']); 3. The dropdown of the people picker opens, because the focus is caught.

Expected behavior The focus of the element should not be caught automatically just because selectUsersById is called. Usually a programmatical selection does not need additional user action.

Environment

  • Browser Edge latest version
  • Framework Angular as custom element

Additional context I am using Angular and use the people picker as a custom element.

web265p3 avatar May 15 '24 11:05 web265p3

Just figured out that this does not happen in older versions. For example in 2.6.2 everything works fine. So this is a bug of the current version 4.2.1

web265p3 avatar May 23 '24 17:05 web265p3

I can't quit figure out how you're using this control @web265p3. Please could you explain a little more how you're utilizing it as a custom element?

musale avatar May 24 '24 11:05 musale

@musale Sorry for my late reply. To use the graph toolkit within my Angular application, I followed the steps from this Microsoft article:

After this steps, you can use the people picker within Angular.

The version 4.2.1 always opens the dropdown menu to pick users after calling the function "selectUsersById". This bug did not happen in older versions, so I just reverted my code to version 2.6.2, where the problem did not exist.

web265p3 avatar Jun 13 '24 13:06 web265p3

Oh, I see what you mean @web265p3. The selectUsersById function is calling addPerson method which adds the found user ids and sets focus on the input field. I introduced this behaviour in this PR https://github.com/microsoftgraph/microsoft-graph-toolkit/pull/2792.

What I would suggest is:

  • expanding the selectUsersById API to have a focusOnInput argument that is by default true and you can call it with false to avoid the focus.
  • an attribute (focus-input) that when set to false, does not focus on the input field. This will affect majority of all other features of the people-picker.

Are these better ways to fix this for you or you have other ideas? v2.x.x is far back I would really want you to use the latest version of MGT too.

musale avatar Jun 20 '24 11:06 musale

Hello Musale,

Thanks! Nice to know that the reason for my problem seems obvious. I am fine with both approaches. Whatever is easier for you to implement. I would also love to use the latest version, so adding just an additional parameter would be awesome. Can you update the documentation?

web265p3 avatar Jul 02 '24 07:07 web265p3

I just saw you closed the issue. I updated to version 4.2.4, but the issue still happens. Also there is no new parameter in the function.

This is the signature of the current version:

/**
 * Queries the microsoft graph for a user based on the user id and adds them to the selectedPeople array
 *
 * @param {readonly string []} an array of user ids to add to selectedPeople
 * @returns {Promise<void>}
 * @memberof MgtPeoplePicker
 */
selectUsersById(userIds) {

///...

}

web265p3 avatar Sep 05 '24 06:09 web265p3

@web265p3 is it still happening in v4.2.5? We realized we did not need to add in a new parameter, we added logic to only open the dropdown when the input is focused, which solved the issue. https://mgt.dev/?path=/story/components-mgt-people-picker-html--select-users-by-id

Mnickii avatar Sep 05 '24 07:09 Mnickii

I just found version 4.2.4 - probably I need to wait a little:

https://www.npmjs.com/package/@microsoft/mgt

web265p3 avatar Sep 05 '24 11:09 web265p3

@web265p3 you're right, it's not yet available. Seems one of our release jobs got a little stuck, we are working on this and it will be available ASAP

Mnickii avatar Sep 05 '24 13:09 Mnickii

@web265p3 should now be available, thank you for your patience!

Mnickii avatar Sep 05 '24 13:09 Mnickii

Thanks, now it works! Very nice ;)

web265p3 avatar Sep 09 '24 05:09 web265p3