Skip to content

Commit 19e1545

Browse files
authored
Merge pull request #1675 from pnp/userPicker
User picker
2 parents a9c6c37 + 12383b5 commit 19e1545

32 files changed

+1661
-49416
lines changed
92.8 KB
Loading
103 KB
Loading
47.9 KB
Loading
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# User Picker
2+
3+
This control allows you to select one or more user from a AAD via its name or starting characters.
4+
5+
!
6+
7+
**Empty user picker**
8+
9+
![Empty user picker](../assets/userPicker03.png)
10+
11+
**Selecting Users**
12+
13+
![Selecting users](../assets/userPicker02.png)
14+
15+
**Selected users in picker**
16+
17+
![Selected users in the input](../assets/userPicker01.png)
18+
19+
## How to use this control in your solutions
20+
21+
- Check that you installed the `@pnp/spfx-controls-react` dependency. Check out the [getting started](../../#getting-started) page for more information about installing the dependency.
22+
- Import the following modules to your component:
23+
24+
```TypeScript
25+
import { UserPicker } from '@pnp/spfx-controls-react/lib/userPicker';
26+
import { IUserInfo } from '@pnp/spfx-controls-react/lib/userPicker/models/IUserInfo';
27+
```
28+
29+
- Use the `UserPicker` control in your code as follows:
30+
31+
```TypeScript
32+
<UserPicker
33+
context={context}
34+
secondaryTextPropertyName="mail"
35+
theme={theme}
36+
label={
37+
<div className={styles.attributeHader}>
38+
<Person20Filled color={tokens.colorBrandForeground1} />
39+
<Body1>Select User</Body1>
40+
</div>
41+
}
42+
placeholder={"Search User"}
43+
onSelectedUsers={onSelectedUsers}
44+
onRemoveSelectedUser={onRemovedUser}
45+
/>
46+
```
47+
48+
- With the `onSelectedUsers` property you can capture the event of when the user in the picker has changed:
49+
50+
```typescript
51+
const onSelectedUsers = React.useCallback((users: IUserInfo[]) => {
52+
console.log(users);
53+
}, []);
54+
```
55+
56+
- With the `onRemoveSelectedUser` property you can capture the event, when the user is removed from picker.
57+
58+
```typescript
59+
const onRemovedUser = React.useCallback((user: IUserInfo) => {
60+
console.log(user);
61+
}, []);
62+
```
63+
64+
## Implementation
65+
66+
The UseryPicker control can be configured with the following properties:
67+
68+
| Property | Type | Required | Description |
69+
| ------------------------- | --------------------------------------------------------------------------------------------------------------------- | -------- | --------------------------------------------------------------- |
70+
| userSelectionLimit | number | no | Number selected users allowed |
71+
| label | string or JSX.Element | no | Text or control displayed above the User Picker. |
72+
| required | boolean | no | Specify if the control is required |
73+
| context | BaseComponentContext | yes | Context of the current web part or extension. |
74+
| validationMessage | string | no | Defines message to show on picker |
75+
| messageType | "error", "success" , "warning" , "none" | no | Defines message type to show if validationMessage is defined |
76+
| onSelectedUsers | (users: IUserInfo[]) => void | no | captures the event of when the users in the picker has changed. |
77+
| onRemoveSelectedUser | (user: IUserInfo) => void | no | captures the event of when the user in the picker was removed |
78+
| placeholder | string | no | placeholder to show |
79+
| defaultSelectdUsers | IUserInfo[] | no | default users to show on the picker |
80+
| theme | IReadonlyTheme | no | theme |
81+
| secondaryTextPropertyName | values :"jobTitle" , "department" , "mail", "officeLocation" , "mobilePhone" , "businessPhones" , "userPrincipalName" | no | secondary text to show on persona card |
82+
83+
Interface `IUserInfo` extends User interface from `@microsoft/microsoft-graph-types``
84+
85+
| Property | Type | Required | Description |
86+
| --------- | -------- | -------- | -------------------------------- |
87+
| userPhoto | string | yes | userPhoto to show on Person card |
88+
| presence | Presence | yes | user Presence |
89+
90+
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/UserPicker)

0 commit comments

Comments
 (0)