Skip to content

Commit 3968c46

Browse files
Merge pull request #1663 from NishkalankBezawada/Issue-374
Fixing Issue 374 - Added a new property to People Picker
2 parents 8863fa6 + a02ed31 commit 3968c46

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

docs/documentation/docs/controls/PeoplePicker.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { PeoplePicker, PrincipalType } from "@pnp/spfx-controls-react/lib/People
3838
showtooltip={true}
3939
required={true}
4040
disabled={true}
41+
searchTextLimit={5}
4142
onChange={this._getPeoplePickerItems}
4243
showHiddenInUI={false}
4344
principalTypes={[PrincipalType.User]}
@@ -83,6 +84,7 @@ The People picker control can be configured with the following properties:
8384
| resolveDelay | number | no | Add delay to resolve and search users | 200 |
8485
| placeholder | string | no | Short text hint to display in empty picker |
8586
| styles | Partial<IBasePickerStyles> | no | Styles to apply on control |
87+
| searchTextLimit | number | no | Specifies the minimum character count needed to begin retrieving search results. | 2 |
8688

8789
Enum `PrincipalType`
8890

src/controls/peoplepicker/IPeoplePicker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export interface IPeoplePickerProps {
3737
* Maximum number of suggestions to show in the full suggestion list. (default: 5)
3838
*/
3939
suggestionsLimit?: number;
40+
/**
41+
* Specifies the minimum character count needed to begin retrieving search results. (default : 2)
42+
*/
43+
searchTextLimit?: number;
4044
/**
4145
* Specify the user / group types to retrieve
4246
*/

src/controls/peoplepicker/PeoplePickerComponent.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
2020
private peopleSearchService: SPPeopleSearchService;
2121
private suggestionsLimit: number;
2222
private groupId: number | string | (string | number)[];
23+
private searchTextCount: number;
2324

2425
constructor(props: IPeoplePickerProps) {
2526
super(props);
2627

2728
this.peopleSearchService = new SPPeopleSearchService(props.context);
2829
this.suggestionsLimit = this.props.suggestionsLimit ? this.props.suggestionsLimit : 5;
30+
this.searchTextCount = this.props.searchTextLimit ? this.props.searchTextLimit : 2;
2931

3032
telemetry.track('ReactPeoplePicker', {
3133
groupName: !!props.groupName,
@@ -135,7 +137,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
135137
* A search field change occured
136138
*/
137139
private onSearchFieldChanged = async (searchText: string, currentSelected: IPersonaProps[]): Promise<IPersonaProps[]> => {
138-
if (searchText.length > 2) {
140+
if (searchText.length > this.searchTextCount) {
139141
const results = await this.peopleSearchService.searchPeople(searchText, this.suggestionsLimit, this.props.principalTypes, this.props.webAbsoluteUrl, this.groupId, this.props.ensureUser, this.props.allowUnvalidated);
140142
// Remove duplicates
141143
const { selectedPersons, mostRecentlyUsedPersons } = this.state;

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
15101510
<PeoplePicker context={this.props.context}
15111511
titleText="People Picker (tenant scoped)"
15121512
personSelectionLimit={10}
1513+
searchTextLimit={5} //New property : Specifies the minimum character count needed to begin retrieving search results. (default : 2)
15131514
// groupName={"Team Site Owners"}
15141515
showtooltip={true}
15151516
required={true}

0 commit comments

Comments
 (0)