Skip to content

Commit

Permalink
onPanelSelectionChange for TaxonomyPicker (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
AJIXuMuK committed Dec 27, 2020
1 parent 13a1c72 commit 0cfed90
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/documentation/docs/controls/TaxonomyPicker.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ The TaxonomyPicker control can be configured with the following properties:
| onGetErrorMessage | (value: IPickerTerms) => string \| Promise&lt;string&gt; | no | The method is used to get the validation error message and determine whether the picker value is valid or not. Mutually exclusive with the static string `errorMessage` (it will take precedence over this).<br />When it returns string:<ul><li>If valid, it returns empty string.</li><li>If invalid, it returns the error message string to be shown below the picker.</li></ul><br />When it returns Promise&lt;string&gt;:<ul><li>The resolved value is display as error message.</li><li>The rejected, the value is thrown away.</li></ul> |
| required | boolean | no | Specifies if to display an asterisk near the label. Note that error message should be specified in `onGetErrorMessage` or `errorMessage` |
| useSessionStorage | boolean | no | Specify if the control uses session storage. Default is set to true for better performance. |
| onPanelSelectionChange | (prevValue: IPickerTerms, newValue: IPickerTerms) => void | no | Panel selection change handler. Can be used to interact with the control while selecting items in the panel, before Click or Cancel is clicked. |


Interface `IPickerTerm`
Expand Down
5 changes: 5 additions & 0 deletions src/controls/taxonomyPicker/ITaxonomyPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ export interface ITaxonomyPickerProps {
* Default will be true
*/
useSessionStorage?: boolean;

/**
* Panel selection change handler. Can be used to interact with the control while selecting items in the panel, before Click or Cancel is clicked.
*/
onPanelSelectionChange?: (prevValue: IPickerTerms, newValue: IPickerTerms) => void;
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/controls/taxonomyPicker/TaxonomyPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
*/
private termsChanged(term: ITerm, checked: boolean): void {

let activeNodes = this.state.activeNodes;
let activeNodes = this.state.activeNodes.slice();
if (typeof term === 'undefined' || term === null) {
return;
}
Expand Down Expand Up @@ -262,10 +262,16 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
}
// Sort all active nodes
activeNodes = sortBy(activeNodes, 'path');

if (this.props.onPanelSelectionChange) {
this.props.onPanelSelectionChange(this.state.activeNodes.slice(), activeNodes)
}

// Update the current state
this.setState({
activeNodes: activeNodes
});

}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/webparts/controlsTest/components/ControlsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,11 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
// new TermLabelAction("Get Labels")
],
termActionsDisplayMode: TermActionsDisplayMode.buttons,
termActionsDisplayStyle: TermActionsDisplayStyle.textAndIcon
termActionsDisplayStyle: TermActionsDisplayStyle.textAndIcon,
}}
onPanelSelectionChange={(prev, next) => {
console.log(prev);
console.log(next);
}}
/>

Expand Down

0 comments on commit 0cfed90

Please sign in to comment.