|
| 1 | +# FolderPicker control |
| 2 | + |
| 3 | +This control allows you to explore and select a folder. |
| 4 | +It also allows the user to create a new folder at the current level being explored. |
| 5 | + |
| 6 | +Here is an example of the control: |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +`FolderPicker` no selection: |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +`FolderPicker` selection: |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +`FolderPicker` selected: |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +## How to use this control in your solutions |
| 23 | + |
| 24 | +- Check that you installed the `@pnp/spfx-controls-react` dependency. Check out the [getting started](../../#getting-started) page for more information about installing the dependency. |
| 25 | +- Import the control into your component: |
| 26 | + |
| 27 | +```TypeScript |
| 28 | +import { FolderPicker, IFolder } from "@pnp/spfx-controls-react/lib/FolderPicker"; |
| 29 | +``` |
| 30 | + |
| 31 | +- Use the `FolderPicker` control in your code as follows: |
| 32 | + |
| 33 | +```TypeScript |
| 34 | +<FolderPicker context={this.props.context} |
| 35 | + label='Folder Picker' |
| 36 | + required={true} |
| 37 | + rootFolder={{ |
| 38 | + Name: 'Documents', |
| 39 | + ServerRelativeUrl: `/sites/TestSite/Shared Documents` |
| 40 | + }} |
| 41 | + onSelect={this._onFolderSelect} |
| 42 | + canCreateFolders={true} /> |
| 43 | +``` |
| 44 | + |
| 45 | +- The `onSelect` change event returns the selected folder and can be implemented as follows: |
| 46 | + |
| 47 | +```TypeScript |
| 48 | +private _onFolderSelect = (folder: IFolder): void => { |
| 49 | + console.log('selected folder', folder); |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +## Implementation |
| 54 | + |
| 55 | +The `FolderPicker` control can be configured with the following properties: |
| 56 | + |
| 57 | +| Property | Type | Required | Description | |
| 58 | +| ---- | ---- | ---- | ---- | |
| 59 | +| context | WebPartContext \| ExtensionContext | yes | The context object of the SPFx loaded webpart or customizer. | |
| 60 | +| label | string | yes | The label for the control. | |
| 61 | +| rootFolder | IFolder | yes | The lowest level folder that can be explored. This can be the root folder of a library. | |
| 62 | +| defaultFolder | IFolder | no | The default folder to be selected or explored. | |
| 63 | +| required | boolean | no | Is selection required. | |
| 64 | +| disabled | boolean | no | Is the control disabled. | |
| 65 | +| canCreateFolders | boolean | no | Allow current user to create folders on the target location. If enabled, you need to ensure that the user has the required permissions. | |
| 66 | +| onSelect | (folder: IFolder): void | no | Callback function called after a folder is selected. | |
| 67 | + |
| 68 | + |
0 commit comments