Skip to content

Commit 32bfb6f

Browse files
committed
Updated show all users when groupName is empty, added mkdocs and commented console logs
1 parent 62d2727 commit 32bfb6f

File tree

7 files changed

+77
-14
lines changed

7 files changed

+77
-14
lines changed
4.02 KB
Loading
20.5 KB
Loading
7.64 KB
Loading
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
![People Picker](../assets/Peoplepicker-witherrorandtooltip.png)
8+
9+
**Selecting People**
10+
11+
![Selecting People](../assets/Peoplepicker-selectingchoices.png)
12+
13+
**Selected people**
14+
15+
![Selected people](../assets/Peoplepicker-multiplechoices.png)
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+
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/PeoplePicker)

src/controls/peoplepicker/IPeoplePicker.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ export interface IPeoplePickerProps {
1313
/**
1414
* Name of SharePoint Group
1515
*/
16-
groupName?: string;
17-
/**
18-
* image Initials
19-
*/
20-
getAllUsers?: boolean;
16+
groupName: string;
2117
/**
2218
* Text of the Control
2319
*/

src/controls/peoplepicker/PeoplePickerComponent.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
2929

3030
public static defaultProps: IPeoplePickerProps = {
3131
context : null,
32-
getAllUsers: true,
3332
titleText: "People Picker",
3433
personSelectionLimit: 1,
3534
showtooltip : false,
@@ -73,7 +72,6 @@ constructor(props: IPeoplePickerProps) {
7372
appInsights.track('ReactPeoplePicker', {
7473
groupName: !!props.groupName,
7574
name: !!props.groupName,
76-
getAllUsers: !!props.getAllUsers,
7775
titleText: !!props.titleText
7876
});
7977

@@ -90,13 +88,13 @@ constructor(props: IPeoplePickerProps) {
9088

9189
private _thisLoadUsers() : void {
9290
var stringVal = "";
93-
if(this.props.getAllUsers)
91+
if(this.props.groupName != "")
9492
{
95-
stringVal = "/_api/web/siteusers";
93+
stringVal = `/_api/web/sitegroups/GetByName('${this.props.groupName}')/users`;
9694
}
97-
else if(this.props.groupName != "")
95+
else
9896
{
99-
stringVal = `/_api/web/sitegroups/GetByName('${this.props.groupName}')/users`;
97+
stringVal = "/_api/web/siteusers";
10098
}
10199

102100
const restApi = `${this.props.context.pageContext.web.absoluteUrl}${stringVal}`;
@@ -251,8 +249,8 @@ public render(): React.ReactElement<IPeoplePickerProps> {
251249
removeButtonAriaLabel={ 'Remove' }
252250
inputProps={ {
253251
'aria-label': 'People Picker',
254-
onBlur: (ev: React.FocusEvent<HTMLInputElement>) => console.log('onBlur on People Picker called'),
255-
onFocus: (ev: React.FocusEvent<HTMLInputElement>) => console.log('onFocus on People Picker called'),
252+
//onBlur: (ev: React.FocusEvent<HTMLInputElement>) => console.log('onBlur on People Picker called'),
253+
//onFocus: (ev: React.FocusEvent<HTMLInputElement>) => console.log('onFocus on People Picker called'),
256254
} }
257255
itemLimit={this.props.personSelectionLimit}
258256
onChange = { this._onPersonItemsChange }

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
284284
<PeoplePicker
285285
context={this.props.context}
286286
titleText="People Picker"
287-
getAllUsers={false}
288287
personSelectionLimit={3}
289288
groupName = {"Team Site Owners"}
290289
showtooltip = {true}

0 commit comments

Comments
 (0)