|
| 1 | +# People Picker |
| 2 | + |
| 3 | +This control renders a People picker field which can be used to select one or many users from a SharePoint group, or filter from all users in a SharePoint site. You could also set the control as mandatory and show a custom error message if field is empty. |
| 4 | + |
| 5 | +**Empty People Picker control with error message and tooltip** |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +**Selecting People** |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +**Selected people** |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +## How to use this control in your solutions |
| 19 | + |
| 20 | +- 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. |
| 21 | +- Import the following modules to your component: |
| 22 | + |
| 23 | +```TypeScript |
| 24 | +import { PeoplePicker } from "@pnp/spfx-controls-react/lib/PeoplePicker"; |
| 25 | +``` |
| 26 | + |
| 27 | +- Use the `PeoplePicker` control in your code as follows: |
| 28 | + |
| 29 | +```TypeScript |
| 30 | +<PeoplePicker |
| 31 | + context={this.props.context} |
| 32 | + titleText="People Picker" |
| 33 | + personSelectionLimit={3} |
| 34 | + groupName = {"Team Site Owners"} //leave this blank in case you want to filter from all users |
| 35 | + showtooltip = {true} |
| 36 | + isRequired = {true} |
| 37 | + selectedItems = {this._getPeoplePickerItems} |
| 38 | +/> |
| 39 | +``` |
| 40 | + |
| 41 | +- With the `selectedItems` property you can get the selected People in the Peoplepicker : |
| 42 | + |
| 43 | +```typescript |
| 44 | +private _getPeoplePickerItems(items: any[]) { |
| 45 | + console.log('Items:', items); |
| 46 | + } |
| 47 | +``` |
| 48 | + |
| 49 | +## Implementation |
| 50 | + |
| 51 | +The People picker control can be configured with the following properties: |
| 52 | + |
| 53 | +| Property | Type | Required | Description | |
| 54 | +| ---- | ---- | ---- | ---- | |
| 55 | +| context | WebPartContext | yes | Context of the current web part. | |
| 56 | +| groupName | string | yes | group from which users are fetched. Leave it blank if need to filter all users | |
| 57 | +| titleText | string | yes | Text to be displayed on the control | |
| 58 | +| personSelectionLimit | number | no | Defines the limit of people that can be selected in the control| |
| 59 | +| isRequired | boolean | no | Set if the control is required or not | |
| 60 | +| errorMessage | string | no | Specify the error message to display | |
| 61 | +| errorMessageclassName | string | no | applies custom styling to the error message section| |
| 62 | +| showtooltip | boolean | no | Defines if need a tooltip or not | |
| 63 | +| tooltip | string | no | Specify the tooltip message to display | |
| 64 | +| tooltipDirectional | DirectionalHint | no | Direction where the tooltip would be shown | |
| 65 | +| selectedItems | function | no | get the selected users in the control| |
| 66 | +| peoplePickerWPclassName | string | no | applies custom styling to the people picker element| |
| 67 | +| peoplePickerCntrlclassName | string | no | applies custom styling to the people picker control only| |
| 68 | + |
| 69 | + |
| 70 | + |
0 commit comments