You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/spfx/extensions/guidance/using-custom-dialogs-with-spfx.md
+51-49Lines changed: 51 additions & 49 deletions
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,29 @@
1
-
# Using Custom Dialogs with SharePoint Framework Extensions
1
+
# Use custom dialog boxes with SharePoint Framework Extensions
2
2
3
-
Custom dialogs are available from the **@microsoft/sp-dialog** package and can be used within the context of SharePoint Framework Extensions or client-side web parts.
3
+
You can use custom dialog boxes, available from the **@microsoft/sp-dialog** package, within the context of SharePoint Framework Extensions or client-side web parts.
4
4
5
-
This tutorial demonstrates the creation of a custom dialog and using it within the context of a ListView Command Set extension.
5
+
This article describes how to create a custom dialog box and use it within the context of a ListView Command Set extension.
6
6
7
-
> The SharePoint Framework dialog is currently in preview status and we are looking to collect feedback before it's officially released. Please provide feedback by using the [sp-dev-docs repository Issue list](https://github.com/SharePoint/sp-dev-docs/issues).
7
+
>**Note:** The custom dialog box feature is currently in preview. We are looking for your feedback before we release. To provide feedback, [file an issue in our GitHub repo](https://github.com/SharePoint/sp-dev-docs/issues).
8
8
9
9
> Please note that debugging Custom ListView Command Sets in SharePoint Online is currently only available from the modern list experience within classic team sites hosted in a **developer tenant**.
10
10
11
-
> The end result of this tutorial is available as source code at https://github.com/SharePoint/sp-dev-fx-extensions/tree/master/samples/react-command-dialog.
12
11
13
-
## Setup your Environment
12
+
You can access the sample code that this article is based on in the [](https://github.com/SharePoint/sp-dev-fx-extensions/tree/master/samples/react-command-dialog) repo.
14
13
15
-
Before you can complete this guide, you will need to ensure you have [setup your environment](https://dev.office.com/sharepoint/docs/spfx/set-up-your-development-environment) for development
16
-
using the SharePoint Framework (SPFx) and that you are using the latest SharePoint Framework Yeoman templates.
14
+
## Set up your development environment
17
15
18
-
> You can update your SharePoint Framework Yeoman templates by running the following command:
19
-
> ```sh
20
-
> npm install -g @microsoft/generator-sharepoint`
21
-
>```
16
+
To create a custom dialog box, you'll need to follow the steps in the [Set up your development environment](https://dev.office.com/sharepoint/docs/spfx/set-up-your-development-environment). Make sure that you're using the latest SharePoint Framework Yeoman templates.
22
17
23
-
## Create a New Project
18
+
To update your SharePoint Framework Yeoman templates, run the following command:
24
19
25
-
Start by creating a new folder for the project using your console of choice:
20
+
```sh
21
+
npm install -g @microsoft/generator-sharepoint`
22
+
```
23
+
24
+
## Create a new project
25
+
26
+
Create a new folder for the project using your console of choice:
26
27
27
28
```sh
28
29
md dialog-cmd
@@ -34,7 +35,7 @@ Then enter that folder:
34
35
cd dialog-cmd
35
36
```
36
37
37
-
Then run the Yeoman generator for the SharePoint Framework:
38
+
Run the Yeoman generator for the SharePoint Framework:
38
39
39
40
```sh
40
41
yo @microsoft/sharepoint
@@ -59,17 +60,17 @@ When the scaffold is complete, you should see the following message indicating a
> For information about troubleshooting any errors, see [Known issues](../basics/known-issues).
63
+
>**Note:** For information about troubleshooting any errors, see [Known issues](../basics/known-issues).
63
64
64
-
Once the scaffolding completes, open your project folder in your code editor. This article uses Visual Studio Code in the steps and screenshots, but you can use any editor you prefer. To open the folder in Visual Studio Code use the following commandin the console:
65
+
When the scaffolding is complete, open your project folder in your code editor. This article uses Visual Studio Code in the steps and screenshots, but you can use any editor you prefer. To open the folder in Visual Studio Code, use the following commandin the console:
65
66
66
67
```sh
67
68
code .
68
69
```
69
70
70
71

71
72
72
-
## Modify the Extension Manifest
73
+
## Modify the extension manifest
73
74
74
75
In the extension manifest, configure the extension to have only one button. In the code editor, open the **./src/extensions/dialogDemo/DialogDemoCommandSet.manifest.json** file. Replace the commands section with the following JSON:
75
76
@@ -85,24 +86,25 @@ In the extension manifest, configure the extension to have only one button. In t
85
86
}
86
87
```
87
88
88
-
## Adding the sp-dialog Package to the Solution
89
+
## Add the sp-dialog package to the solution
89
90
90
-
Return to the console and execute the following command to include the dialog API in your solution:
91
+
Return to the console and run the following command to include the dialog API in your solution:
91
92
92
93
```sh
93
94
npm install @microsoft/sp-dialog --save
94
95
```
95
96
96
-
Since we are using the `--save` option, this dependency will be added to the **package.json** file. This will ensure that it will be automatically installed when the `npm install`commandis executed (this is important when restoring or cloning your project elsewhere).
97
+
Because you're using the `--save` option, this dependency will be added to the **package.json** file. This ensures that it will be installed automatically when the `npm install` command runs (this is important when you restore or clone your project elsewhere).
97
98
98
99
Return to Visual Studio Code (or your preferred editor).
99
100
100
-
## Creating a Custom Dialog
101
+
## Create a custom dialog box
102
+
101
103
Create a new file called **ColorPickerDialog.tsx** in the **./src/extensions/dialogDemo/** folder.
102
104
103
-
Add the following import statements at the top of the newly created file. We are creating our custom dialog using the [Office UI Fabric React components](https://dev.office.com/fabric#/components), so the implementation will be in React.
105
+
Add the following import statements at the top of the newly created file. You're creating your custom dialog box using the [Office UI Fabric React components](https://dev.office.com/fabric#/components), so the implementation will be in React.
104
106
105
-
> Currently the `DialogContent` component is coming from `@microsoft/sp-dialog`, but will be included as part of the Office UI Fabric React components soon, as mentioned in the code comments below.
107
+
>**Note:**Currently the `DialogContent` component is coming from `@microsoft/sp-dialog`, but it will be included as part of the Office UI Fabric React components soon.
106
108
107
109
```ts
108
110
import * as React from 'react';
@@ -121,7 +123,7 @@ import {
121
123
import { DialogContent } from '@microsoft/sp-dialog';
122
124
```
123
125
124
-
Add the following interface definition just below the import statements. This wil be used to pass information and functions between your ListView Command Set extension and your custom dialog.
126
+
Add the following interface definition just below the import statements. This will be used to pass information and functions between your ListView Command Set extension and your custom dialog box.
Add the following class just below the interface definition. This React class is responsible for rendering the UI experiences inside of the custom dialog. Notice that we use the Office UI Fabric React components for actual rendering and just pass the needed properties.
137
+
Add the following class just below the interface definition. This React class is responsible for rendering the UI experiences inside the custom dialog box. Notice that you use the Office UI Fabric React components for actual rendering and just pass the needed properties.
136
138
137
139
```ts
138
140
class ColorPickerDialogContent extends React.Component<IColorPickerDialogContentProps, {}> {
@@ -165,7 +167,7 @@ class ColorPickerDialogContent extends React.Component<IColorPickerDialogContent
165
167
}
166
168
}
167
169
```
168
-
Add the following class definition forour custom dialog under the just added `ColorPickerDialogContent` class. This is the actual custom dialog which will be called from the ListView Command Set button click and is inherited from the `BaseDialog`.
170
+
Add the following class definition foryour custom dialog box under the `ColorPickerDialogContent` class that you just added. This is the actual custom dialog box that will be called from the ListView Command Set button click and is inherited from the `BaseDialog`.
169
171
170
172
```ts
171
173
export default class ColorPickerDialog extends BaseDialog {
## Associating the Custom Dialog with the ListView Command Set Button Click
199
-
To associate the custom dialog with your custom ListView Command Set, the code to initiate the dialog has to be added within the button click operation.
200
+
## Associate the custom dialog box with the ListView Command Set button click
201
+
To associate the custom dialog box with your custom ListView Command Set, add the code to initiate the dialog box within the button click operation.
200
202
201
203
In the code editor, open the **DialogDemoCommandSet.ts** file from the **./src/extensions/dialogDemo/** folder.
202
204
203
-
Add the following import statements under the existing **strings** import. These are forusing the just created custom dialogin the context of your ListView Command Set.
205
+
Add the following import statements under the existing **strings** import. These are forusing the custom dialog boxin the context of your ListView Command Set.
204
206
205
207
```ts
206
208
import { Dialog } from '@microsoft/sp-dialog';
207
209
import ColorPickerDialog from './ColorPickerDialog';
208
210
```
209
211
210
-
Add the following `_colorCode` variable definition above the `onInit`functionin the `DialogDemoCommandSet` class. This is used to store the color picker dialog result.
212
+
Add the following `_colorCode` variable definition above the `onInit`functionin the `DialogDemoCommandSet` class. This is used to store the color picker dialog box result.
211
213
212
214
```ts
213
215
private _colorCode: string;
214
216
```
215
217
216
-
Update the `onExecute`functionas follows. In this code we are doing the following:
218
+
Update the `onExecute`functionas follows. This code does the following:
217
219
218
-
*Initiate our custom dialog
219
-
*Pass a message for the dialog, which will be used as the title
220
-
*Pass a color code for the dialog with a default value, if not yet set
221
-
*Show our custom dialog
222
-
*Receive and store the return value from the dialog
223
-
*Show the received value inan out-of-the-box dialog using the `Dialog.alert()` function
220
+
*Initiates the custom dialog box.
221
+
*Passes a message for the dialog box, which is used for the title.
222
+
*Passed a color code for the dialog box with a default value, if not yet set.
223
+
*Shows the custom dialog box.
224
+
*Receives and stores the return value from the dialog box.
225
+
*Shows the received value ina default dialog box using the `Dialog.alert()` function.
224
226
225
227
```ts
226
228
@override
@@ -242,44 +244,44 @@ Update the `onExecute` function as follows. In this code we are doing the follow
242
244
}
243
245
```
244
246
245
-
## Testing the Custom Dialog in your Tenant
247
+
## Test the custom dialog box in your tenant
246
248
247
-
Open the **DialogDemoCommandSet.manifest.json** file in**./src/extensions/dialogDemo/** folder and copy the **id** value, which will be used in the debug query parameter.
249
+
Open the **DialogDemoCommandSet.manifest.json** file inthe **./src/extensions/dialogDemo/** folder and copy the **id** value, which will be used in the debug query parameter.
248
250
249
-
Return to the console and execute the following command:
251
+
Return to the console and run the following command:
250
252
251
253
```sh
252
254
gulp serve --nobrowser
253
255
```
254
256
255
-
Notice that we used the `--nobrowser` option, since there's no value in launching the local workbench since you currently cannot debug extensions locally.
257
+
Notice that you use the `--nobrowser` option. You don't need to launch the local workbench because you currently cannot debug extensions locally.
256
258
257
259
This will start the bundling of your solution and will serve the resulting manifest from the `localhost` address.
258
260
259
261

260
262
261
-
To test your extension, navigate to a site in your SharePoint Online developer tenant.
263
+
To test your extension, go to a site in your SharePoint Online developer tenant.
262
264
263
-
Navigate to an existing custom list within the site with some items or create a new list and add a few items to it for testing purposes.
265
+
Go to an existing custom list within the site that contains some items, or create a new list and add a few items to it for testing purposes.
264
266
265
267
Append the following query string parameters to the URL. Notice that you will need to update the **id** to match your own extension identifier as listed in the **DialogDemoCommandSet.manifest.json** file:
Choose a color in the *Color Picker* and click **OK** to test how the code is returning the selected value back to the caller. The selection is then shown using the out-of-the-box alert dialog.
285
+
Choose a color in the *Color Picker* and choose **OK** to test how the code is returning the selected value back to the caller. The selection is then shown using the default alert dialog box.
0 commit comments