Skip to content

Commit 4b61a1c

Browse files
ListItemPicker add property to show all options by default
1 parent 143d5a1 commit 4b61a1c

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

docs/documentation/docs/controls/ListItemPicker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@ The `ListItemPicker` control can be configured with the following properties:
6565
| placeholder | string | no | Short text hint to display in empty picker |
6666
| substringSearch | boolean | no | Specifies if substring search should be used |
6767
| label | string | no | Specifies the text describing the ListItemPicker. |
68+
| enableDefaultSuggestions | boolean | no | Enable default suggestions. All options are displayed by default when clicking on the control. |
6869

6970
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/ListItemPicker)

src/controls/listItemPicker/IListItemPickerProps.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ export interface IListItemPickerProps {
2828
*/
2929
label?: string;
3030

31+
/**
32+
* Enable default suggestions. All options are displayed by default when clicking on the control
33+
*/
34+
enableDefaultSuggestions?: boolean;
35+
3136
}

src/controls/listItemPicker/ListItemPicker.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getId } from 'office-ui-fabric-react/lib/Utilities';
77
import { IListItemPickerProps, IListItemPickerState } from ".";
88
import * as telemetry from '../../common/telemetry';
99
import isEqual from 'lodash/isEqual';
10+
import { ITag } from 'office-ui-fabric-react/lib/components/pickers/TagPicker/TagPicker.types';
1011

1112

1213
export class ListItemPicker extends React.Component<IListItemPickerProps, IListItemPickerState> {
@@ -74,6 +75,11 @@ export class ListItemPicker extends React.Component<IListItemPickerProps, IListI
7475
}
7576
<div id={this._tagPickerId}>
7677
<TagPicker onResolveSuggestions={this.onFilterChanged}
78+
onEmptyResolveSuggestions={(selectLists) => {
79+
if (this.props.enableDefaultSuggestions) {
80+
return this.onFilterChanged("", selectLists);
81+
}
82+
}}
7783
// getTextFromItem={(item: any) => { return item.name; }}
7884
getTextFromItem={this.getTextFromItem}
7985
pickerSuggestionsProps={{
@@ -115,8 +121,8 @@ export class ListItemPicker extends React.Component<IListItemPickerProps, IListI
115121
/**
116122
* Filter Change
117123
*/
118-
private onFilterChanged = async (filterText: string, tagList: { key: string; name: string }[]) => {
119-
let resolvedSugestions: { key: string; name: string }[] = await this.loadListItems(filterText);
124+
private onFilterChanged = async (filterText: string, tagList: ITag[]) => {
125+
let resolvedSugestions: ITag[] = await this.loadListItems(filterText);
120126

121127
const {
122128
selectedItems

src/services/SPService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ export default class SPService implements ISPService {
114114
}
115115
else {
116116
const filterStr = substringSearch ? // JJ - 20200613 - find by substring as an option
117-
`substringof('${encodeURIComponent(filterText.replace("'", "''"))}',${internalColumnName})${filterString ? ' and ' + filterString : ''}`
118-
: `startswith(${internalColumnName},'${encodeURIComponent(filterText.replace("'", "''"))}')${filterString ? ' and ' + filterString : ''}`; //string = filterList ? `and ${filterList}` : '';
117+
`${filterText ? `substringof('${encodeURIComponent(filterText.replace("'", "''"))}',${internalColumnName})` : ''}${filterString ? (filterText ? ' and ' : '') + filterString : ''}`
118+
: `${filterText ? `startswith(${internalColumnName},'${encodeURIComponent(filterText.replace("'", "''"))}')` : ''}${filterString ? (filterText ? ' and ' : '') + filterString : ''}`; //string = filterList ? `and ${filterList}` : '';
119119
apiUrl = `${webAbsoluteUrl}/_api/web/lists('${listId}')/items?$select=${keyInternalColumnName || 'Id'},${internalColumnName}&$filter=${filterStr}&$orderby=${orderBy}`;
120120
}
121121

0 commit comments

Comments
 (0)