Skip to content

Commit

Permalink
Placeholder for ListItemPicker, ListPicker, and PeoplePicker, depreca…
Browse files Browse the repository at this point in the history
…tion of placeHolder for ListPicker
  • Loading branch information
AJIXuMuK committed Feb 23, 2020
1 parent 376b042 commit 9b0d4d1
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 40 deletions.
1 change: 1 addition & 0 deletions docs/documentation/docs/controls/ListItemPicker.md
Expand Up @@ -60,5 +60,6 @@ The `ListItemPicker` control can be configured with the following properties:
| noResultsFoundText | string | no | The text that should appear when no results are returned. |
| disabled | boolean | no | Specifies if the control is disabled or not. |
| filter | string | no | condition to filter list Item, same as $filter ODATA parameter|
| placeholder | string | no | Short text hint to display in empty picker |

![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/ListItemPicker)
1 change: 1 addition & 0 deletions docs/documentation/docs/controls/ListPicker.md
Expand Up @@ -59,6 +59,7 @@ The `ListPicker` control can be configured with the following properties:
| selectedList | string OR string[] | no | Keys of the selected item(s). If you provide this, you must maintain selection state by observing onSelectionChanged events and passing a new value in when changed. |
| multiSelect | boolean | no | Optional mode indicates if multi-choice selections is allowed. Default to `false`. |
| label | string | no | Label to use for the control. |
| placeHolder | string | no | Placeholder label to show in the dropdown. **Deprecated. Use `placeholder` instead.** |
| placeholder | string | no | Placeholder label to show in the dropdown. |
| onSelectionChanged | (newValue: string OR string[]): void | no | Callback function when the selected option changes. |

Expand Down
1 change: 1 addition & 0 deletions docs/documentation/docs/controls/PeoplePicker.md
Expand Up @@ -75,6 +75,7 @@ The People picker control can be configured with the following properties:
| ensureUser | boolean | no | When ensure user property is true, it will return the local user ID on the current site when doing a tenant wide search. | false |
| suggestionsLimit | number | no | Maximum number of suggestions to show in the full suggestion list. | 5 |
| resolveDelay | number | no | Add delay to resolve and search users | 200 |
| placeholder | string | no | Short text hint to display in empty picker |

Enum `PrincipalType`

Expand Down
4 changes: 4 additions & 0 deletions src/controls/listItemPicker/IListItemPickerProps.ts
Expand Up @@ -14,6 +14,10 @@ export interface IListItemPickerProps {
disabled?: boolean;
suggestionsHeaderText?:string;
noResultsFoundText?:string;
/**
* Placeholder to be displayed in an empty term picker
*/
placeholder?: string;

onSelectedItem: (item:any) => void;
}
7 changes: 5 additions & 2 deletions src/controls/listItemPicker/ListItemPicker.tsx
Expand Up @@ -41,7 +41,7 @@ export class ListItemPicker extends React.Component<IListItemPickerProps, IListI
* Render the field
*/
public render(): React.ReactElement<IListItemPickerProps> {
const { className, disabled, itemLimit } = this.props;
const { className, disabled, itemLimit, placeholder } = this.props;

return (
<div>
Expand All @@ -56,7 +56,10 @@ export class ListItemPicker extends React.Component<IListItemPickerProps, IListI
onChange={this.onItemChanged}
className={className}
itemLimit={itemLimit}
disabled={disabled} />
disabled={disabled}
inputProps={{
placeholder: placeholder
}} />

<Label style={{color:'#FF0000'}}> {this.state.errorMessage} </Label>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/controls/listPicker/IListPicker.ts
Expand Up @@ -49,6 +49,10 @@ export interface IListPickerProps {
* Input placeholder text. Displayed until option is selected.
*/
placeHolder?: string;
/**
* Input placeholder text. Displayed until option is selected.
*/
placeholder?: string;
/**
* Callback issues when the selected option changes
*/
Expand Down
4 changes: 2 additions & 2 deletions src/controls/listPicker/ListPicker.tsx
Expand Up @@ -144,14 +144,14 @@ export class ListPicker extends React.Component<IListPickerProps, IListPickerSta
*/
public render(): JSX.Element {
const { loading, options, selectedList } = this.state;
const { className, disabled, multiSelect, label, placeHolder } = this.props;
const { className, disabled, multiSelect, label, placeHolder, placeholder } = this.props;

const dropdownOptions: IDropdownProps = {
className: className,
options: options,
disabled: ( loading || disabled ),
label: label,
placeHolder: placeHolder,
placeHolder: placeholder || placeHolder,
onChanged: this.onChanged
};

Expand Down
4 changes: 4 additions & 0 deletions src/controls/peoplepicker/IPeoplePicker.ts
Expand Up @@ -94,6 +94,10 @@ export interface IPeoplePickerProps {
* When ensure user property is true, it will return the local user ID on the current site when doing a tenant wide search
*/
ensureUser?: boolean;
/**
* Placeholder to be displayed in an empty term picker
*/
placeholder?: string;
}

export interface IPeoplePickerState {
Expand Down
93 changes: 59 additions & 34 deletions src/controls/peoplepicker/PeoplePickerComponent.tsx
Expand Up @@ -55,9 +55,9 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
*/
public componentWillUpdate(nextProps: IPeoplePickerProps, nextState: IPeoplePickerState): void {
if (!isEqual(this.props.defaultSelectedUsers, nextProps.defaultSelectedUsers) ||
this.props.groupName !== nextProps.groupName ||
this.props.webAbsoluteUrl !== nextProps.webAbsoluteUrl ||
this.peopleSearchService.getSumOfPrincipalTypes(this.props.principalTypes) !== this.peopleSearchService.getSumOfPrincipalTypes(nextProps.principalTypes)) {
this.props.groupName !== nextProps.groupName ||
this.props.webAbsoluteUrl !== nextProps.webAbsoluteUrl ||
this.peopleSearchService.getSumOfPrincipalTypes(this.props.principalTypes) !== this.peopleSearchService.getSumOfPrincipalTypes(nextProps.principalTypes)) {
this.getInitialPersons(nextProps);
}
}
Expand Down Expand Up @@ -101,7 +101,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
/**
* A search field change occured
*/
private onSearchFieldChanged = async (searchText: string, currentSelected: IPersonaProps[]): Promise<IPersonaProps[]> => {
private onSearchFieldChanged = async (searchText: string, currentSelected: IPersonaProps[]): Promise<IPersonaProps[]> => {
if (searchText.length > 2) {
const results = await this.peopleSearchService.searchPeople(searchText, this.suggestionsLimit, this.props.principalTypes, this.props.webAbsoluteUrl, this.groupId, this.props.ensureUser);
// Remove duplicates
Expand Down Expand Up @@ -176,64 +176,89 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
* Default React component render method
*/
public render(): React.ReactElement<IPeoplePickerProps> {

const {
peoplePickerCntrlclassName,
peoplePickerWPclassName,
isRequired,
titleText,
suggestionsLimit,
placeholder,
personSelectionLimit,
disabled,
showtooltip,
tooltipMessage,
tooltipDirectional,
errorMessageClassName,
errorMessage
} = this.props;

const {
selectedPersons,
resolveDelay,
errorMessage: stateErrorMessage,
showRequiredError
} = this.state;

const suggestionProps: IBasePickerSuggestionsProps = {
suggestionsHeaderText: strings.peoplePickerSuggestionsHeaderText,
noResultsFoundText: strings.genericNoResultsFoundText,
loadingText: strings.peoplePickerLoadingText,
resultsMaximumNumber: this.props.suggestionsLimit ? this.props.suggestionsLimit : 5,
resultsMaximumNumber: suggestionsLimit ? suggestionsLimit : 5,
searchingText: strings.PeoplePickerSearchText
};


const peoplepicker = (
<div id="people" className={`${styles.defaultClass} ${this.props.peoplePickerWPclassName ? this.props.peoplePickerWPclassName : ''}`}>
{this.props.titleText && <Label required={this.props.isRequired}>{this.props.titleText}</Label>}
<div id="people" className={`${styles.defaultClass} ${peoplePickerWPclassName ? peoplePickerWPclassName : ''}`}>
{titleText && <Label required={isRequired}>{titleText}</Label>}

<NormalPeoplePicker pickerSuggestionsProps={suggestionProps}
onResolveSuggestions={this.onSearchFieldChanged}
onEmptyInputFocus={this.returnMostRecentlyUsedPerson}
getTextFromItem={(peoplePersonaMenu: IPersonaProps) => peoplePersonaMenu.text}
className={`ms-PeoplePicker ${this.props.peoplePickerCntrlclassName ? this.props.peoplePickerCntrlclassName : ''}`}
key={'normal'}
removeButtonAriaLabel={'Remove'}
inputProps={{
'aria-label': 'People Picker'
}}
selectedItems={this.state.selectedPersons}
itemLimit={this.props.personSelectionLimit || 1}
disabled={this.props.disabled || !!this.state.errorMessage}
onChange={this.onChange}
resolveDelay={this.state.resolveDelay} />
onResolveSuggestions={this.onSearchFieldChanged}
onEmptyInputFocus={this.returnMostRecentlyUsedPerson}
getTextFromItem={(peoplePersonaMenu: IPersonaProps) => peoplePersonaMenu.text}
className={`ms-PeoplePicker ${peoplePickerCntrlclassName ? peoplePickerCntrlclassName : ''}`}
key={'normal'}
removeButtonAriaLabel={'Remove'}
inputProps={{
'aria-label': 'People Picker',
placeholder: placeholder
}}
selectedItems={selectedPersons}
itemLimit={personSelectionLimit || 1}
disabled={disabled || !!stateErrorMessage}
onChange={this.onChange}
resolveDelay={resolveDelay} />
</div>
);

return (
<div>
{
this.props.showtooltip ? (
<TooltipHost content={this.props.tooltipMessage || strings.peoplePickerComponentTooltipMessage}
id='pntp'
calloutProps={{ gapSpace: 0 }}
directionalHint={this.props.tooltipDirectional || DirectionalHint.leftTopEdge}>
showtooltip ? (
<TooltipHost content={tooltipMessage || strings.peoplePickerComponentTooltipMessage}
id='pntp'
calloutProps={{ gapSpace: 0 }}
directionalHint={tooltipDirectional || DirectionalHint.leftTopEdge}>
{peoplepicker}
</TooltipHost>
) : (
<div>
{peoplepicker}
</div>
)
<div>
{peoplepicker}
</div>
)
}

{
((this.props.isRequired && this.state.showRequiredError) || (this.state.errorMessage)) && (
<p className={`ms-TextField-errorMessage ${styles.errorMessage} ${this.props.errorMessageClassName ? this.props.errorMessageClassName : ''}`}>
((isRequired && showRequiredError) || (stateErrorMessage)) && (
<p className={`ms-TextField-errorMessage ${styles.errorMessage} ${errorMessageClassName ? errorMessageClassName : ''}`}>
<Icon iconName='Error' className={styles.errorIcon} />
{
this.state.errorMessage && <span data-automation-id="error-message">{this.state.errorMessage}</span>
stateErrorMessage && <span data-automation-id="error-message">{stateErrorMessage}</span>
}

{
(this.props.isRequired && this.state.showRequiredError) && <span data-automation-id="error-message">{this.props.errorMessage ? this.props.errorMessage : strings.peoplePickerComponentErrorMessage}</span>
(isRequired && showRequiredError) && <span data-automation-id="error-message">{errorMessage ? errorMessage : strings.peoplePickerComponentErrorMessage}</span>
}
</p>
)
Expand Down
6 changes: 4 additions & 2 deletions src/webparts/controlsTest/components/ControlsTest.tsx
Expand Up @@ -516,7 +516,8 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
showHiddenInUI={false}
principalTypes={[PrincipalType.User, PrincipalType.SharePointGroup, PrincipalType.SecurityGroup, PrincipalType.DistributionList]}
suggestionsLimit={2}
resolveDelay={200} />
resolveDelay={200}
placeholder={'Select a SharePoint principal (User or Group)'} />

<PeoplePicker context={this.props.context}
titleText="People Picker (local scoped)"
Expand Down Expand Up @@ -684,7 +685,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
<div className="ms-font-m">List picker tester:
<ListPicker context={this.props.context}
label="Select your list(s)"
placeHolder="Select your list(s)"
placeholder="Select your list(s)"
baseTemplate={100}
includeHidden={false}
multiSelect={true}
Expand All @@ -700,6 +701,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
filter={"Title eq 'SPFx'"}
itemLimit={5}
context={this.props.context}
placeholder={'Select list items'}
onSelectedItem={this.listItemPickerDataSelected} />

</div>
Expand Down

1 comment on commit 9b0d4d1

@AJIXuMuK
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implements #486

Please sign in to comment.