|
| 1 | +# FolderExplorer control |
| 2 | + |
| 3 | +This control allows you to explore a folder structure by clinking on a folder to load it's sub-folders and using a breadcrumb navigation to navigate back to a previous level. |
| 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 | +`FolderExplorer` folder creation: |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +## How to use this control in your solutions |
| 15 | + |
| 16 | +- 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. |
| 17 | +- Import the control into your component: |
| 18 | + |
| 19 | +```TypeScript |
| 20 | +import { FolderExplorer, IFolder } from "@pnp/spfx-controls-react/lib/FolderExplorer"; |
| 21 | +``` |
| 22 | + |
| 23 | +- Use the `FolderExplorer` control in your code as follows: |
| 24 | + |
| 25 | +```TypeScript |
| 26 | +<FolderExplorer |
| 27 | + context={this.props.context} |
| 28 | + rootFolder={{ |
| 29 | + Name: 'Documents', |
| 30 | + ServerRelativeUrl: `/sites/TestSite/Shared Documents` |
| 31 | + }} |
| 32 | + defaultFolder={{ |
| 33 | + Name: 'Documents', |
| 34 | + ServerRelativeUrl: `/sites/TestSite/Shared Documents` |
| 35 | + }} |
| 36 | + onSelect={this._onFolderSelect} |
| 37 | + canCreateFolders={true} |
| 38 | + /> |
| 39 | +``` |
| 40 | + |
| 41 | +- The `onSelect` change event returns the selected folder and can be implemented as follows: |
| 42 | + |
| 43 | +```TypeScript |
| 44 | +private _onFolderSelect = (folder: IFolder): void => { |
| 45 | + console.log('selected folder', folder); |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +## Implementation |
| 50 | + |
| 51 | +The `FolderExplorer` control can be configured with the following properties: |
| 52 | + |
| 53 | +| Property | Type | Required | Description | |
| 54 | +| ---- | ---- | ---- | ---- | |
| 55 | +| context | WebPartContext \| ExtensionContext | yes | The context object of the SPFx loaded webpart or customizer. | |
| 56 | +| rootFolder | IFolder | yes | The lowest level folder that can be explored. This can be the root folder of a library. | |
| 57 | +| defaultFolder | IFolder | yes | The default folder to be explored. | |
| 58 | +| 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. | |
| 59 | +| hiddenBreadcrumb | boolean | no | Hide the breadcrumb control. | |
| 60 | +| hiddenFilterBox | boolean | no | Hide the filter box | |
| 61 | +| onSelect | (folder: IFolder): void | no | Callback function called after a folder is selected. | |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
0 commit comments