|
| 1 | +# Modern Taxonomy Picker |
| 2 | + |
| 3 | +This control allows you to select one or more Terms from a TermSet via its TermSet ID. You can also configure the control to select the child terms from a specific term in the TermSet by setting the anchorTermId. This is the modern version of the taxonomy picker that uses the REST API and makes use of some load on demand features which makes it well suited for large term sets. |
| 4 | + |
| 5 | +!!! note "Disclaimer" |
| 6 | + Since this control is meant to look as and work in the same way as the out-of-the-box control it lacks some of the features from the legacy ```TaxonomyPicker``` control. If you need some of those features please continue using the legacy version. |
| 7 | + |
| 8 | +**Empty term picker** |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +**Selecting terms** |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +**Selected terms in picker** |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +**Term picker: Auto Complete** |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +## How to use this control in your solutions |
| 26 | + |
| 27 | +- 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. |
| 28 | +- Import the following modules to your component: |
| 29 | + |
| 30 | +```TypeScript |
| 31 | +import { ModernTaxonomyPicker } from "@pnp/spfx-controls-react/lib/ModernTaxonomyPicker"; |
| 32 | +``` |
| 33 | + |
| 34 | +- Use the `ModernTaxonomyPicker` control in your code as follows: |
| 35 | + |
| 36 | +```TypeScript |
| 37 | +<ModernTaxonomyPicker allowMultipleSelections={true} |
| 38 | + termSetId="f233d4b7-68fb-41ef-8b58-2af0bafc0d38" |
| 39 | + panelTitle="Select Term" |
| 40 | + label="Taxonomy Picker" |
| 41 | + context={this.props.context} |
| 42 | + onChange={this.onTaxPickerChange} /> |
| 43 | +``` |
| 44 | + |
| 45 | +- With the `onChange` property you can capture the event of when the terms in the picker has changed: |
| 46 | + |
| 47 | +```typescript |
| 48 | +private onTaxPickerChange(terms : ITermInfo[]) { |
| 49 | + console.log("Terms", terms); |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +## Implementation |
| 54 | + |
| 55 | +The ModernTaxonomyPicker control can be configured with the following properties: |
| 56 | + |
| 57 | +| Property | Type | Required | Description | |
| 58 | +| ---- | ---- | ---- | ---- | |
| 59 | +| panelTitle | string | yes | TermSet Picker Panel title. | |
| 60 | +| label | string | yes | Text displayed above the Taxonomy Picker. | |
| 61 | +| disabled | boolean | no | Specify if the control should be disabled. Default value is false. | |
| 62 | +| context | BaseComponentContext | yes | Context of the current web part or extension. | |
| 63 | +| initialValues | ITermInfo[] | no | Defines the terms selected by default. ITermInfo comes from PnP/PnPjs and can be imported with <br/>```import { ITermInfo } from '@pnp/sp/taxonomy';``` | |
| 64 | +| allowMultipleSelections | boolean | no | Defines if the user can select only one or multiple terms. Default value is false. | |
| 65 | +| termSetId | string | yes | The Id of the TermSet that you would like the Taxonomy Picker to select terms from. | |
| 66 | +| onChange | function | no | Captures the event of when the terms in the picker has changed. | |
| 67 | +| anchorTermId | string | no | Set the id of a child term in the TermSet to be able to select terms from that level and below. | |
| 68 | +| placeHolder | string | no | Short text hint to display in picker. | |
| 69 | +| required | boolean | no | Specifies if to display an asterisk near the label. Default value is false. | |
| 70 | +| customPanelWidth | number | no | Custom panel width in pixels. | |
| 71 | +| termPickerProps | IModernTermPickerProps | no | Custom properties for the term picker (More info: [IBasePickerProps interface](https://developer.microsoft.com/en-us/fluentui#/controls/web/pickers#IBasePickerProps)). | |
| 72 | +| themeVariant | IReadonlyTheme | no | The current loaded SharePoint theme/section background (More info: [Supporting section backgrounds](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/guidance/supporting-section-backgrounds)). | |
| 73 | + |
| 74 | + |
0 commit comments