Skip to content

Commit 0cfed90

Browse files
committed
onPanelSelectionChange for TaxonomyPicker (#761)
1 parent 13a1c72 commit 0cfed90

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

docs/documentation/docs/controls/TaxonomyPicker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ The TaxonomyPicker control can be configured with the following properties:
172172
| 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> |
173173
| required | boolean | no | Specifies if to display an asterisk near the label. Note that error message should be specified in `onGetErrorMessage` or `errorMessage` |
174174
| useSessionStorage | boolean | no | Specify if the control uses session storage. Default is set to true for better performance. |
175+
| 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. |
175176

176177

177178
Interface `IPickerTerm`

src/controls/taxonomyPicker/ITaxonomyPicker.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ export interface ITaxonomyPickerProps {
126126
* Default will be true
127127
*/
128128
useSessionStorage?: boolean;
129+
130+
/**
131+
* Panel selection change handler. Can be used to interact with the control while selecting items in the panel, before Click or Cancel is clicked.
132+
*/
133+
onPanelSelectionChange?: (prevValue: IPickerTerms, newValue: IPickerTerms) => void;
129134
}
130135

131136
/**

src/controls/taxonomyPicker/TaxonomyPicker.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
231231
*/
232232
private termsChanged(term: ITerm, checked: boolean): void {
233233

234-
let activeNodes = this.state.activeNodes;
234+
let activeNodes = this.state.activeNodes.slice();
235235
if (typeof term === 'undefined' || term === null) {
236236
return;
237237
}
@@ -262,10 +262,16 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
262262
}
263263
// Sort all active nodes
264264
activeNodes = sortBy(activeNodes, 'path');
265+
266+
if (this.props.onPanelSelectionChange) {
267+
this.props.onPanelSelectionChange(this.state.activeNodes.slice(), activeNodes)
268+
}
269+
265270
// Update the current state
266271
this.setState({
267272
activeNodes: activeNodes
268273
});
274+
269275
}
270276

271277
/**

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,11 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
746746
// new TermLabelAction("Get Labels")
747747
],
748748
termActionsDisplayMode: TermActionsDisplayMode.buttons,
749-
termActionsDisplayStyle: TermActionsDisplayStyle.textAndIcon
749+
termActionsDisplayStyle: TermActionsDisplayStyle.textAndIcon,
750+
}}
751+
onPanelSelectionChange={(prev, next) => {
752+
console.log(prev);
753+
console.log(next);
750754
}}
751755
/>
752756

0 commit comments

Comments
 (0)