Skip to content

Commit 19eecab

Browse files
authored
Add label to list item picker
* Combobox Label and Spinner * ListItemPickerLabel * Added Prop to Docs
1 parent 1eb5461 commit 19eecab

File tree

8 files changed

+68
-44
lines changed

8 files changed

+68
-44
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
@@ -62,5 +62,6 @@ The `ListItemPicker` control can be configured with the following properties:
6262
| filter | string | no | condition to filter list Item, same as $filter ODATA parameter|
6363
| placeholder | string | no | Short text hint to display in empty picker |
6464
| substringSearch | boolean | no | Specifies if substring search should be used |
65+
| label | string | no | Specifies the text describing the ListItemPicker. |
6566

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

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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: 24 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){
78+
if (onInitialized) {
7779
onInitialized();
7880
}
7981
}
@@ -90,33 +92,35 @@ export class ComboBoxListItemPicker extends React.Component<IComboBoxListItemPic
9092
public render(): React.ReactElement<IComboBoxListItemPickerProps> {
9193
const { className, disabled } = this.props;
9294

93-
return (this.state.availableOptions ? (
94-
<div>
95-
<ComboBox options={this.state.availableOptions}
96-
autoComplete={this.props.autoComplete}
97-
comboBoxOptionStyles={this.props.comboBoxOptionStyles}
98-
allowFreeform={this.props.allowFreeform}
99-
keytipProps={this.props.keytipProps}
100-
onMenuDismissed={this.props.onMenuDismiss}
101-
onMenuOpen={this.props.onMenuOpen}
102-
text={this.props.text}
103-
onChanged={this.onChanged}
104-
multiSelect={this.props.multiSelect}
105-
defaultSelectedKey={this.selectedItems.map(item=>item.key) || []}
106-
className={className}
107-
disabled={disabled} />
108-
95+
return (
96+
<div className={styles.comboBoxListItemPickerWrapper}>
97+
<ComboBox
98+
label={this.props.label}
99+
options={this.state.availableOptions}
100+
autoComplete={this.props.autoComplete}
101+
comboBoxOptionStyles={this.props.comboBoxOptionStyles}
102+
allowFreeform={this.props.allowFreeform}
103+
keytipProps={this.props.keytipProps}
104+
onMenuDismissed={this.props.onMenuDismiss}
105+
onMenuOpen={this.props.onMenuOpen}
106+
text={this.props.text}
107+
onChanged={this.onChanged}
108+
multiSelect={this.props.multiSelect}
109+
defaultSelectedKey={this.selectedItems.map(item => item.key) || []}
110+
className={className}
111+
disabled={disabled || !this.state.availableOptions} />
112+
{!this.state.errorMessage && !this.state.availableOptions && (<Spinner className={styles.loading} size={SpinnerSize.small} />)}
109113
{!!this.state.errorMessage &&
110114
(<Label style={{ color: '#FF0000' }}> {this.state.errorMessage} </Label>)}
111-
</div>) : <span>Loading...</span>
115+
</div>
112116
);
113117
}
114118

115119
/**
116120
* On Selected Item
117121
*/
118122
private onChanged = (option?: IComboBoxOption, index?: number, value?: string, submitPendingValueEvent?: any): void => {
119-
if(this.props.multiSelect){
123+
if (this.props.multiSelect) {
120124
if (option && option.selected) {
121125
this.selectedItems.push({
122126
[this.props.keyColumnInternalName || "Id"]: option.key,
@@ -126,7 +130,7 @@ export class ComboBoxListItemPicker extends React.Component<IComboBoxListItemPic
126130
} else {
127131
this.selectedItems = this.selectedItems.filter(o => o[this.props.keyColumnInternalName || "Id"] !== option.key);
128132
}
129-
}else{
133+
} else {
130134
this.selectedItems.push({
131135
[this.props.keyColumnInternalName || "Id"]: option.key,
132136
[this.props.columnInternalName]: option.text

src/controls/listItemPicker/IComboBoxListItemPickerProps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ export interface IComboBoxListItemPickerProps {
2929
onInitialized?: () => void;
3030

3131
onSelectedItem: (item: any) => void;
32+
label?:string;
3233
}

src/controls/listItemPicker/IListItemPickerProps.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ import { ExtensionContext } from "@microsoft/sp-extension-base";
44
export interface IListItemPickerProps {
55
columnInternalName: string;
66
keyColumnInternalName?: string;
7-
context: WebPartContext | ExtensionContext;
7+
context: WebPartContext | ExtensionContext;
88
listId: string;
99
itemLimit: number;
1010
filter?: string;
1111
className?: string;
1212
webUrl?: string;
1313
defaultSelectedItems?: any[];
1414
disabled?: boolean;
15-
suggestionsHeaderText?:string;
16-
noResultsFoundText?:string;
15+
suggestionsHeaderText?: string;
16+
noResultsFoundText?: string;
1717
substringSearch?: boolean; // JJ - 20200613 - find by substring as an option
1818
/**
1919
* Placeholder to be displayed in an empty term picker
2020
*/
2121
placeholder?: string;
2222

23-
onSelectedItem: (item:any) => void;
23+
onSelectedItem: (item: any) => void;
24+
25+
label?: string;
2426
}

src/controls/listItemPicker/ListItemPicker.tsx

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import { TagPicker } from "office-ui-fabric-react/lib/components/pickers/TagPick
55
import { Label } from "office-ui-fabric-react/lib/Label";
66
import { IListItemPickerProps, IListItemPickerState } from ".";
77
import * as telemetry from '../../common/telemetry';
8+
import { getId } from 'office-ui-fabric-react/lib/Utilities';
89

910

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

1416
constructor(props: IListItemPickerProps) {
1517
super(props);
@@ -44,24 +46,29 @@ export class ListItemPicker extends React.Component<IListItemPickerProps, IListI
4446

4547
return (
4648
<div>
47-
<TagPicker onResolveSuggestions={this.onFilterChanged}
48-
// getTextFromItem={(item: any) => { return item.name; }}
49-
getTextFromItem={this.getTextFromItem}
50-
pickerSuggestionsProps={{
51-
suggestionsHeaderText: this.state.suggestionsHeaderText,
52-
noResultsFoundText: this.state.noresultsFoundText
53-
}}
54-
defaultSelectedItems={this.props.defaultSelectedItems || []}
55-
onChange={this.onItemChanged}
56-
className={className}
57-
itemLimit={itemLimit}
58-
disabled={disabled}
59-
inputProps={{
60-
placeholder: placeholder
61-
}} />
62-
63-
{!!this.state.errorMessage &&
64-
(<Label style={{color:'#FF0000'}}> {this.state.errorMessage} </Label>)}
49+
{!!this.props.label &&
50+
<Label htmlFor={this._tagPickerId} >{this.props.label}</Label>
51+
}
52+
<div id={this._tagPickerId}>
53+
<TagPicker onResolveSuggestions={this.onFilterChanged}
54+
// getTextFromItem={(item: any) => { return item.name; }}
55+
getTextFromItem={this.getTextFromItem}
56+
pickerSuggestionsProps={{
57+
suggestionsHeaderText: this.state.suggestionsHeaderText,
58+
noResultsFoundText: this.state.noresultsFoundText
59+
}}
60+
defaultSelectedItems={this.props.defaultSelectedItems || []}
61+
onChange={this.onItemChanged}
62+
className={className}
63+
itemLimit={itemLimit}
64+
disabled={disabled}
65+
inputProps={{
66+
placeholder: placeholder
67+
}} />
68+
69+
{!!this.state.errorMessage &&
70+
(<Label style={{ color: '#FF0000' }}> {this.state.errorMessage} </Label>)}
71+
</div>
6572
</div>
6673
);
6774
}

0 commit comments

Comments
 (0)