Skip to content

Commit 88e2510

Browse files
authored
Label for list item picker
* Label for list item picker #885 * Docs and Label added to ListPicker
1 parent c76d4e3 commit 88e2510

File tree

7 files changed

+65
-39
lines changed

7 files changed

+65
-39
lines changed

docs/documentation/docs/controls/ComboBoxListItemPicker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,6 @@ The `ComboBoxListItemPicker` control can be configured with the following proper
122122
| multiSelect | boolean | no | Allows multiple selection|
123123
| onInitialized | () => void | no | Calls when component is ready|
124124
| itemLimit | number | no | Maximum number of items to be displayed in the combobox. Default: 100 |
125+
| label | string | no | Specifies the text describing the combobox ListItemPicker. |
125126

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

docs/documentation/docs/controls/ListItemPicker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@ The `ListItemPicker` control can be configured with the following properties:
6464
| orderBy | string | no | condition to order by list Item, same as $orderby ODATA parameter|
6565
| placeholder | string | no | Short text hint to display in empty picker |
6666
| substringSearch | boolean | no | Specifies if substring search should be used |
67+
| label | string | no | Specifies the text describing the ListItemPicker. |
6768

6869
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/ListItemPicker)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.comboBoxListItemPickerWrapper{
2+
position: relative;
3+
.loading{
4+
position: absolute;
5+
right:8px;
6+
bottom:9px;
7+
}
8+
}

src/controls/listItemPicker/ComboBoxListItemPicker.tsx

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { IComboBoxListItemPickerProps, IComboBoxListItemPickerState } from ".";
55
import * as telemetry from '../../common/telemetry';
66
import { ComboBox, IComboBoxOption } from "office-ui-fabric-react/lib/ComboBox";
77
import { ListItemRepository } from '../../common/dal/ListItemRepository';
8+
import styles from './ComboBoxListItemPicker.module.scss';
9+
import { Spinner, SpinnerSize } from 'office-ui-fabric-react';
810

911

1012
export class ComboBoxListItemPicker extends React.Component<IComboBoxListItemPickerProps, IComboBoxListItemPickerState> {
@@ -73,7 +75,7 @@ export class ComboBoxListItemPicker extends React.Component<IComboBoxListItemPic
7375
this.setState({
7476
availableOptions: options
7577
});
76-
if(onInitialized && isInitialLoad !== false){
78+
if (onInitialized && isInitialLoad !== false) {
7779
onInitialized();
7880
}
7981
}
@@ -97,33 +99,34 @@ export class ComboBoxListItemPicker extends React.Component<IComboBoxListItemPic
9799
public render(): React.ReactElement<IComboBoxListItemPickerProps> {
98100
const { className, disabled } = this.props;
99101

100-
return (this.state.availableOptions ? (
101-
<div>
102-
<ComboBox options={this.state.availableOptions}
103-
autoComplete={this.props.autoComplete}
104-
comboBoxOptionStyles={this.props.comboBoxOptionStyles}
105-
allowFreeform={this.props.allowFreeform}
106-
keytipProps={this.props.keytipProps}
107-
onMenuDismissed={this.props.onMenuDismiss}
108-
onMenuOpen={this.props.onMenuOpen}
109-
text={this.props.text}
110-
onChange={(e, value) => this.onChanged(value)}
111-
multiSelect={this.props.multiSelect}
112-
defaultSelectedKey={this.selectedItems.map(item=>item.key) || []}
113-
className={className}
114-
disabled={disabled} />
115-
102+
return (
103+
<div className={styles.comboBoxListItemPickerWrapper}>
104+
<ComboBox label={this.props.label}
105+
options={this.state.availableOptions}
106+
autoComplete={this.props.autoComplete}
107+
comboBoxOptionStyles={this.props.comboBoxOptionStyles}
108+
allowFreeform={this.props.allowFreeform}
109+
keytipProps={this.props.keytipProps}
110+
onMenuDismissed={this.props.onMenuDismiss}
111+
onMenuOpen={this.props.onMenuOpen}
112+
text={this.props.text}
113+
onChange={(e, value) => this.onChanged(value)}
114+
multiSelect={this.props.multiSelect}
115+
defaultSelectedKey={this.selectedItems.map(item => item.key) || []}
116+
className={className}
117+
disabled={disabled} />
118+
{!this.state.errorMessage && !this.state.availableOptions && (<Spinner className={styles.loading} size={SpinnerSize.small} />)}
116119
{!!this.state.errorMessage &&
117120
(<Label style={{ color: '#FF0000' }}> {this.state.errorMessage} </Label>)}
118-
</div>) : <span>Loading...</span>
121+
</div>
119122
);
120123
}
121124

122125
/**
123126
* On Selected Item
124127
*/
125128
private onChanged = (option?: IComboBoxOption, index?: number, value?: string, submitPendingValueEvent?: any): void => {
126-
if(this.props.multiSelect){
129+
if (this.props.multiSelect) {
127130
if (option && option.selected) {
128131
this.selectedItems.push({
129132
[this.props.keyColumnInternalName || "Id"]: option.key,
@@ -133,7 +136,7 @@ export class ComboBoxListItemPicker extends React.Component<IComboBoxListItemPic
133136
} else {
134137
this.selectedItems = this.selectedItems.filter(o => o[this.props.keyColumnInternalName || "Id"] !== option.key);
135138
}
136-
}else{
139+
} else {
137140
this.selectedItems.push({
138141
[this.props.keyColumnInternalName || "Id"]: option.key,
139142
[this.props.columnInternalName]: option.text

src/controls/listItemPicker/IComboBoxListItemPickerProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ export interface IComboBoxListItemPickerProps {
2727
suggestionsHeaderText?: string;
2828
noResultsFoundText?: string;
2929
onInitialized?: () => void;
30-
3130
onSelectedItem: (item: any) => void;
31+
label?: string;
3232
}

src/controls/listItemPicker/IListItemPickerProps.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BaseComponentContext } from '@microsoft/sp-component-base';
22

33
export interface IListItemPickerProps {
4+
45
columnInternalName: string;
56
keyColumnInternalName?: string;
67
context: BaseComponentContext;
@@ -21,4 +22,10 @@ export interface IListItemPickerProps {
2122
placeholder?: string;
2223

2324
onSelectedItem: (item:any) => void;
25+
26+
/**
27+
* The label for the control
28+
*/
29+
label?: string;
30+
2431
}

src/controls/listItemPicker/ListItemPicker.tsx

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import * as React from "react";
33
import SPservice from "../../services/SPService";
44
import { TagPicker } from "office-ui-fabric-react/lib/components/pickers/TagPicker/TagPicker";
55
import { Label } from "office-ui-fabric-react/lib/Label";
6+
import { getId } from 'office-ui-fabric-react/lib/Utilities';
67
import { IListItemPickerProps, IListItemPickerState } from ".";
78
import * as telemetry from '../../common/telemetry';
89
import isEqual from 'lodash/isEqual';
910

1011

1112
export class ListItemPicker extends React.Component<IListItemPickerProps, IListItemPickerState> {
1213
private _spservice: SPservice;
14+
private _tagPickerId = getId('tagPicker');
1315

1416
constructor(props: IListItemPickerProps) {
1517
super(props);
@@ -49,8 +51,8 @@ export class ListItemPicker extends React.Component<IListItemPickerProps, IListI
4951
if (this.props.listId !== nextProps.listId
5052
|| this.props.columnInternalName !== nextProps.columnInternalName
5153
|| this.props.webUrl !== nextProps.webUrl) {
52-
this.loadField(nextProps);
53-
}
54+
this.loadField(nextProps);
55+
}
5456
}
5557

5658
/**
@@ -67,22 +69,26 @@ export class ListItemPicker extends React.Component<IListItemPickerProps, IListI
6769

6870
return (
6971
<div>
70-
<TagPicker onResolveSuggestions={this.onFilterChanged}
71-
// getTextFromItem={(item: any) => { return item.name; }}
72-
getTextFromItem={this.getTextFromItem}
73-
pickerSuggestionsProps={{
74-
suggestionsHeaderText: suggestionsHeaderText,
75-
noResultsFoundText: noresultsFoundText
76-
}}
77-
selectedItems={selectedItems}
78-
onChange={this.onItemChanged}
79-
className={className}
80-
itemLimit={itemLimit}
81-
disabled={disabled}
82-
inputProps={{
83-
placeholder: placeholder
84-
}} />
85-
72+
{!!this.props.label &&
73+
<Label htmlFor={this._tagPickerId} >{this.props.label}</Label>
74+
}
75+
<div id={this._tagPickerId}>
76+
<TagPicker onResolveSuggestions={this.onFilterChanged}
77+
// getTextFromItem={(item: any) => { return item.name; }}
78+
getTextFromItem={this.getTextFromItem}
79+
pickerSuggestionsProps={{
80+
suggestionsHeaderText: suggestionsHeaderText,
81+
noResultsFoundText: noresultsFoundText
82+
}}
83+
selectedItems={selectedItems}
84+
onChange={this.onItemChanged}
85+
className={className}
86+
itemLimit={itemLimit}
87+
disabled={disabled}
88+
inputProps={{
89+
placeholder: placeholder
90+
}} />
91+
</div>
8692
{!!errorMessage &&
8793
(<Label style={{ color: '#FF0000' }}> {errorMessage} </Label>)}
8894
</div>

0 commit comments

Comments
 (0)