|
| 1 | +# SitePicker control |
| 2 | + |
| 3 | +This control allows you to select one or multiple available sites, site collections or hub sites. |
| 4 | + |
| 5 | +Here is an example of the control. |
| 6 | + |
| 7 | +`SitePicker` single selection mode: |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +`SitePicker` multi-selection mode |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +## How to use this control in your solutions |
| 16 | + |
| 17 | +- 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. |
| 18 | +- Import the control into your component: |
| 19 | + |
| 20 | +```TypeScript |
| 21 | +import { SitePicker } from "@pnp/spfx-controls-react/lib/SitePicker"; |
| 22 | +``` |
| 23 | + |
| 24 | +- Use the `SitePicker` control in your code as follows: |
| 25 | + |
| 26 | +```TypeScript |
| 27 | +<SitePicker |
| 28 | + context={this.props.context} |
| 29 | + label={'Select sites'} |
| 30 | + mode={'site'} |
| 31 | + allowSearch={true} |
| 32 | + multiSelect={false} |
| 33 | + onChange={(sites) => { console.log(sites); }} |
| 34 | + placeholder={'Select sites'} |
| 35 | + searchPlaceholder={'Filter sites'} /> |
| 36 | +``` |
| 37 | + |
| 38 | +- The `onChange` change event returns the selected site(s). |
| 39 | + |
| 40 | +## Implementation |
| 41 | + |
| 42 | +The `SitePicker` control can be configured with the following properties: |
| 43 | + |
| 44 | +| Property | Type | Required | Description | |
| 45 | +| ---- | ---- | ---- | ---- | |
| 46 | +| allowSearch | boolean | no | Specifies if search box is displayed for the component. Default: `true`. | |
| 47 | +| context | BaseComponentContext | yes | The context object of the SPFx loaded webpart or customizer. | |
| 48 | +| deferredSearchTime | number | no | The list will be filtered after users stop typing for `deferredSearchTime` milliseconds. Default: 200. | |
| 49 | +| className | string | no | If provided, additional class name to provide on the dropdown element. | |
| 50 | +| disabled | boolean | no | Whether or not the control is disabled. | |
| 51 | +| initialSites | ISite[] | no | Intial data to load in the 'Selected sites' area (optional). | |
| 52 | +| isDesc | boolean | no | Specifies if the list is sorted in descending order. Default: `false`. | |
| 53 | +| label | string | no | Label to use for the control. | |
| 54 | +| limitToCurrentSiteCollection | boolean | no | Specifies if the options should be limited by the current site collections. Taken into consideration if selectionMode is set to `web`. | |
| 55 | +| mode | `'site' \| 'web' \| 'hub'` | no | Defines what entities are available for selection: site collections, sites, hub sites. Default: `web`. | |
| 56 | +| multiSelect | boolean | no | Optional mode indicates if multi-choice selections is allowed. Default: `true`. | |
| 57 | +| onChange | `(selectedSites: ISite[]) => void` | yes | Selection change handler. | |
| 58 | +| orderBy | `'title' \| 'url'` | no | Specifices if the list is sorted by title or url. Default: `title`. | |
| 59 | +| placeholder | string | no | Placeholder label to show in the dropdown. | |
| 60 | +| searchPlaceholder | string | no | Search input placeholder text. Displayed until search text is entered. | |
| 61 | + |
| 62 | +Interface `ISite` |
| 63 | + |
| 64 | +| Property | Type | Required | Description | |
| 65 | +| ---- | ---- | ---- | ---- | |
| 66 | +| id | string | no | ID of the site collection. | |
| 67 | +| title | string | no | Title of the site. | |
| 68 | +| url | string | no | URL of the site. | |
| 69 | +| webId | string | no | ID of the site. **Note: the value is not populated if the `mode` is set to `hub`. | |
| 70 | +| hubSiteId | string | no | ID of the hub site. | |
| 71 | + |
| 72 | + |
0 commit comments