Skip to content

Commit d08ec76

Browse files
committed
Updates on the dropdown articles
1 parent 3b1bb6f commit d08ec76

8 files changed

+55
-66
lines changed

docs/spfx/web-parts/guidance/use-cascading-dropdowns-in-web-part-properties.md

Lines changed: 55 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Use cascading dropdowns in web part properties
22

3-
> Note. This article has not yet been verified with SPFx GA version, so you might have challenges on making this work as such with the latest release.
4-
53
When designing the property pane for your SharePoint client-side web parts, you may have one web part property that displays its options based on the value selected in another property. This scenario typically occurs when implementing cascading dropdown controls. In this article, you will learn how to create cascading dropdown controls in the web part property pane without developing a custom property pane control.
64

75
![Item dropdown disabled and web part placeholder communicating loading updated list of item options](../../../../images/react-cascading-dropdowns-loading-indicator-when-loading-items.png)
@@ -34,9 +32,9 @@ When prompted, enter the following values:
3432

3533
- **react-cascadingdropdowns** as your solution name
3634
- **Use the current folder** for the ___location to place the files
35+
- **React** as the starting point to build the web part
3736
- **List items** as your web part name
3837
- **Shows list items from the selected list** as your web part description
39-
- **React** as the starting point to build the web part
4038

4139
![SharePoint Framework Yeoman generator with the default choices](../../../../images/react-cascading-dropdowns-yo-sharepoint.png)
4240

@@ -81,7 +79,7 @@ Update the **propertyPaneSettings** getter to:
8179
```ts
8280
export default class ListItemsWebPart extends BaseClientSideWebPart<IListItemsWebPartProps> {
8381
// ...
84-
protected get propertyPaneSettings(): IPropertyPaneSettings {
82+
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
8583
return {
8684
pages: [
8785
{
@@ -132,26 +130,17 @@ In the **src/webparts/listItems/components/ListItems.tsx** file, change the cont
132130

133131
```tsx
134132
export default class ListItems extends React.Component<IListItemsProps, {}> {
135-
public render(): JSX.Element {
133+
public render(): JSX.Element {
136134
return (
137-
<div className={styles.listItems}>
135+
<div className={styles.helloWorld}>
138136
<div className={styles.container}>
139-
<div className={css('ms-Grid-row ms-bgColor-themeDark ms-fontColor-white', styles.row)}>
140-
<div className='ms-Grid-col ms-u-lg10 ms-u-xl8 ms-u-xlPush2 ms-u-lgPush1'>
141-
<span className='ms-font-xl ms-fontColor-white'>
142-
Welcome to SharePoint!
143-
</span>
144-
<p className='ms-font-l ms-fontColor-white'>
145-
Customize SharePoint experiences using web parts.
146-
</p>
147-
<p className='ms-font-l ms-fontColor-white'>
148-
{this.props.listName}
149-
</p>
150-
<a
151-
className={css('ms-Button', styles.button)}
152-
href='https://github.com/SharePoint/sp-dev-docs/wiki'
153-
>
154-
<span className='ms-Button-label'>Learn more</span>
137+
<div className={`ms-Grid-row ms-bgColor-themeDark ms-fontColor-white ${styles.row}`}>
138+
<div className="ms-Grid-col ms-u-lg10 ms-u-xl8 ms-u-xlPush2 ms-u-lgPush1">
139+
<span className="ms-font-xl ms-fontColor-white">Welcome to SharePoint!</span>
140+
<p className="ms-font-l ms-fontColor-white">Customize SharePoint experiences using Web Parts.</p>
141+
<p className="ms-font-l ms-fontColor-white">{escape(this.props.listName)}</p>
142+
<a href="https://aka.ms/spfx" className={styles.button}>
143+
<span className={styles.label}>Learn more</span>
155144
</a>
156145
</div>
157146
</div>
@@ -161,6 +150,13 @@ export default class ListItems extends React.Component<IListItemsProps, {}> {
161150
}
162151
}
163152
```
153+
In the **src/webparts/listItems/components/IListItemsProps.ts** file, change the **IListItemsProps** interface to:
154+
155+
```ts
156+
export interface IListItemsProps {
157+
listName: string;
158+
}
159+
```
164160

165161
Run the following command to verify that the project is running:
166162

@@ -183,23 +179,18 @@ In the **ListItemsWebPart** class add a reference to the **PropertyPaneDropdown*
183179
```ts
184180
import {
185181
BaseClientSideWebPart,
186-
IPropertyPaneSettings,
187-
IWebPartContext,
188-
PropertyPaneDropdown
182+
IPropertyPaneConfiguration,
183+
PropertyPaneTextField,
184+
PropertyPaneDropdown,
185+
IPropertyPaneDropdownOption
189186
} from '@microsoft/sp-webpart-base';
190187
```
191188

192-
Right after this import statement, add a reference to the **IDropdownOption** interface.
193-
194-
```ts
195-
import { IDropdownOption } from 'office-ui-fabric-react';
196-
```
197-
198189
In the **ListItemsWebPart** class, add a new variable named **lists** to store information about all available lists in the current site.
199190

200191
```ts
201192
export default class ListItemsWebPart extends BaseClientSideWebPart<IListItemsWebPartProps> {
202-
private lists: IDropdownOption[];
193+
private lists: IPropertyPaneDropdownOption[];
203194
// ...
204195
}
205196
```
@@ -233,7 +224,7 @@ export default class ListItemsWebPart extends BaseClientSideWebPart<IListItemsWe
233224
PropertyPaneDropdown('listName', {
234225
label: strings.ListNameFieldLabel,
235226
options: this.lists,
236-
isDisabled: this.listsDropdownDisabled
227+
disabled: this.listsDropdownDisabled
237228
})
238229
]
239230
}
@@ -264,17 +255,17 @@ In the **ListItemsWebPart** class, add a method to load available lists. In this
264255
```ts
265256
export default class ListItemsWebPart extends BaseClientSideWebPart<IListItemsWebPartProps> {
266257
// ...
267-
private loadLists(): Promise<IDropdownOption[]> {
268-
return new Promise<IDropdownOption[]>((resolve: (options: IDropdownOption[]) => void, reject: (error: any) => void) => {
258+
private loadLists(): Promise<IPropertyPaneDropdownOption[]> {
259+
return new Promise<IPropertyPaneDropdownOption[]>((resolve: (options: IPropertyPaneDropdownOption[]) => void, reject: (error: any) => void) => {
269260
setTimeout((): void => {
270261
resolve([{
271262
key: 'sharedDocuments',
272263
text: 'Shared Documents'
273264
},
274-
{
275-
key: 'myDocuments',
276-
text: 'My Documents'
277-
}]);
265+
{
266+
key: 'myDocuments',
267+
text: 'My Documents'
268+
}]);
278269
}, 2000);
279270
});
280271
}
@@ -298,7 +289,7 @@ export default class ListItemsWebPart extends BaseClientSideWebPart<IListItemsWe
298289
this.context.statusRenderer.displayLoadingIndicator(this.domElement, 'lists');
299290

300291
this.loadLists()
301-
.then((listOptions: IDropdownOption[]): void => {
292+
.then((listOptions: IPropertyPaneDropdownOption[]): void => {
302293
this.lists = listOptions;
303294
this.listsDropdownDisabled = false;
304295
this.context.propertyPane.refresh();
@@ -358,6 +349,15 @@ export interface IListItemsWebPartProps {
358349
}
359350
```
360351

352+
Change the code in the **src/webparts/listItems/components/IListItemsProps.ts** file to:
353+
354+
```ts
355+
export interface IListItemsProps {
356+
listName: string;
357+
itemName: string;
358+
}
359+
```
360+
361361
In the **src/webparts/listItems/ListItemsWebPart.ts** file, change the code of the **render** method to:
362362

363363
```ts
@@ -407,27 +407,16 @@ In the **src/webparts/listItems/components/ListItems.tsx** file, change the **re
407407
export default class ListItems extends React.Component<IListItemsProps, {}> {
408408
public render(): JSX.Element {
409409
return (
410-
<div className={styles.listItems}>
410+
<div className={styles.helloWorld}>
411411
<div className={styles.container}>
412-
<div className={css('ms-Grid-row ms-bgColor-themeDark ms-fontColor-white', styles.row)}>
413-
<div className='ms-Grid-col ms-u-lg10 ms-u-xl8 ms-u-xlPush2 ms-u-lgPush1'>
414-
<span className='ms-font-xl ms-fontColor-white'>
415-
Welcome to SharePoint!
416-
</span>
417-
<p className='ms-font-l ms-fontColor-white'>
418-
Customize SharePoint experiences using web parts.
419-
</p>
420-
<p className='ms-font-l ms-fontColor-white'>
421-
{this.props.listName}
422-
</p>
423-
<p className='ms-font-l ms-fontColor-white'>
424-
{this.props.itemName}
425-
</p>
426-
<a
427-
className={css('ms-Button', styles.button)}
428-
href='https://github.com/SharePoint/sp-dev-docs/wiki'
429-
>
430-
<span className='ms-Button-label'>Learn more</span>
412+
<div className={`ms-Grid-row ms-bgColor-themeDark ms-fontColor-white ${styles.row}`}>
413+
<div className="ms-Grid-col ms-u-lg10 ms-u-xl8 ms-u-xlPush2 ms-u-lgPush1">
414+
<span className="ms-font-xl ms-fontColor-white">Welcome to SharePoint!</span>
415+
<p className="ms-font-l ms-fontColor-white">Customize SharePoint experiences using Web Parts.</p>
416+
<p className="ms-font-l ms-fontColor-white">{escape(this.props.listName)}</p>
417+
<p className="ms-font-l ms-fontColor-white">{escape(this.props.itemName)}</p>
418+
<a href="https://aka.ms/spfx" className={styles.button}>
419+
<span className={styles.label}>Learn more</span>
431420
</a>
432421
</div>
433422
</div>
@@ -447,7 +436,7 @@ In the **ListItemsWebPart** class, add a new variable named **items** which you
447436
```ts
448437
export default class ListItemsWebPart extends BaseClientSideWebPart<IListItemsWebPartProps> {
449438
// ...
450-
private items: IDropdownOption[];
439+
private items: IPropertyPaneDropdownOption[];
451440
// ...
452441
}
453442
```
@@ -467,7 +456,7 @@ Change the **propertyPaneSettings** getter to use the dropdown control to render
467456
```ts
468457
export default class ListItemsWebPart extends BaseClientSideWebPart<IListItemsWebPartProps> {
469458
// ...
470-
protected get propertyPaneSettings(): IPropertyPaneSettings {
459+
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
471460
return {
472461
pages: [
473462
{
@@ -481,12 +470,12 @@ export default class ListItemsWebPart extends BaseClientSideWebPart<IListItemsWe
481470
PropertyPaneDropdown('listName', {
482471
label: strings.ListNameFieldLabel,
483472
options: this.lists,
484-
isDisabled: this.listsDropdownDisabled
473+
disabled: this.listsDropdownDisabled
485474
}),
486475
PropertyPaneDropdown('itemName', {
487476
label: strings.ItemNameFieldLabel,
488477
options: this.items,
489-
isDisabled: this.itemsDropdownDisabled
478+
disabled: this.itemsDropdownDisabled
490479
})
491480
]
492481
}
@@ -517,15 +506,15 @@ In the **src/webparts/listItems/ListItemsWebPart.ts** file, in the **ListItemsWe
517506
```ts
518507
export default class ListItemsWebPart extends BaseClientSideWebPart<IListItemsWebPartProps> {
519508
// ...
520-
private loadItems(): Promise<IDropdownOption[]> {
509+
private loadItems(): Promise<IPropertyPaneDropdownOption[]> {
521510
if (!this.properties.listName) {
522511
// resolve to empty options since no list has been selected
523512
return Promise.resolve();
524513
}
525514

526515
const wp: ListItemsWebPart = this;
527516

528-
return new Promise<IDropdownOption[]>((resolve: (options: IDropdownOption[]) => void, reject: (error: any) => void) => {
517+
return new Promise<IPropertyPaneDropdownOption[]>((resolve: (options: IPropertyPaneDropdownOption[]) => void, reject: (error: any) => void) => {
529518
setTimeout(() => {
530519
const items = {
531520
sharedDocuments: [
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)