1
1
import * as React from 'react' ;
2
2
import styles from './TaxonomyPanelContents.module.scss' ;
3
- import { Checkbox , ChoiceGroup , GroupedList , GroupHeader , IBasePickerStyleProps , IBasePickerStyles , ICheckboxStyleProps , ICheckboxStyles , IChoiceGroupOption , IChoiceGroupOptionStyleProps , IChoiceGroupOptionStyles , IGroup , IGroupFooterProps , IGroupHeaderProps , IGroupHeaderStyleProps , IGroupHeaderStyles , IGroupRenderProps , IGroupShowAllProps , ILabelStyleProps , ILabelStyles , ILinkStyleProps , ILinkStyles , IListProps , IRenderFunction , ISpinnerStyleProps , ISpinnerStyles , IStyleFunctionOrObject , ITag , Label , Link , Selection , Spinner , TagPicker } from 'office-ui-fabric-react' ;
3
+ import { Checkbox , ChoiceGroup , GroupedList , GroupHeader , IBasePickerStyleProps , IBasePickerStyles , ICheckboxStyleProps , ICheckboxStyles , IChoiceGroupOption , IChoiceGroupOptionStyleProps , IChoiceGroupOptionStyles , IGroup , IGroupFooterProps , IGroupHeaderProps , IGroupHeaderStyleProps , IGroupHeaderStyles , IGroupRenderProps , IGroupShowAllProps , ILabelStyleProps , ILabelStyles , ILinkStyleProps , ILinkStyles , IListProps , IRenderFunction , ISpinnerStyleProps , ISpinnerStyles , IStyleFunctionOrObject , ITag , Label , Link , Selection , SelectionMode , SelectionZone , Spinner , TagPicker } from 'office-ui-fabric-react' ;
4
4
import { ITermInfo , ITermSetInfo , ITermStoreInfo } from '@pnp/sp/taxonomy' ;
5
5
import { Guid } from '@microsoft/sp-core-library' ;
6
6
import { BaseComponentContext } from '@microsoft/sp-component-base' ;
@@ -194,58 +194,61 @@ export function TaxonomyPanelContents(props: ITaxonomyFormProps): React.ReactEle
194
194
}
195
195
} ;
196
196
197
- const onChoiceChange = ( ev ?: React . FormEvent < HTMLElement | HTMLInputElement > , option ?: IChoiceGroupOption ) : void => {
198
- selection . setAllSelected ( false ) ;
199
- selection . setKeySelected ( option . key , true , true ) ;
200
- } ;
201
-
202
- const onCheckboxChange = ( ev ?: React . FormEvent < HTMLElement | HTMLInputElement > , checked ?: boolean , tag ?: ITag ) : void => {
203
- if ( checked ) {
204
- selection . setKeySelected ( tag . key . toString ( ) , true , true ) ;
205
- }
206
- else {
207
- selection . setKeySelected ( tag . key . toString ( ) , false , true ) ;
208
- }
209
- } ;
210
-
211
197
const onRenderTitle = ( groupHeaderProps : IGroupHeaderProps ) => {
212
198
const isChildSelected = ( children : IGroup [ ] ) : boolean => {
213
199
let aChildIsSelected = children && children . some ( ( child ) => selection . isKeySelected ( child . key ) || isChildSelected ( child . children ) ) ;
214
200
return aChildIsSelected ;
215
201
} ;
216
202
217
- const isBold = isChildSelected ( groupHeaderProps . group . children ) ;
203
+ const childIsSelected = isChildSelected ( groupHeaderProps . group . children ) ;
218
204
219
205
if ( groupHeaderProps . group . level === 0 ) {
220
- const labelStyles : IStyleFunctionOrObject < ILabelStyleProps , ILabelStyles > = { root : { fontWeight : isBold ? "bold" : "normal" } } ;
206
+ const labelStyles : IStyleFunctionOrObject < ILabelStyleProps , ILabelStyles > = { root : { fontWeight : childIsSelected ? "bold" : "normal" } } ;
221
207
return (
222
208
< Label styles = { labelStyles } > { groupHeaderProps . group . name } </ Label >
223
209
) ;
224
210
}
225
211
212
+ const isDisabled = groupHeaderProps . group . data . term . isAvailableForTagging . filter ( ( t ) => t . setId === props . termSetId . toString ( ) ) [ 0 ] . isAvailable === false ;
213
+ const isSelected = selection . isKeySelected ( groupHeaderProps . group . key ) ;
214
+
215
+ const selectionProps = {
216
+ "data-selection-index" : selection . getItems ( ) . findIndex ( ( term ) => term . key === groupHeaderProps . group . key )
217
+ } ;
218
+
226
219
if ( props . allowMultipleSelections ) {
227
- const isSelected = selection . isKeySelected ( groupHeaderProps . group . key ) ;
228
- const selectedStyles : IStyleFunctionOrObject < ICheckboxStyleProps , ICheckboxStyles > = isSelected || isBold ? { label : { fontWeight : 'bold' } } : { label : { fontWeight : 'normal' } } ;
220
+ if ( isDisabled ) {
221
+ selectionProps [ "data-selection-disabled" ] = true ;
222
+ }
223
+ else {
224
+ selectionProps [ "data-selection-toggle" ] = true ;
225
+ }
226
+
227
+ const selectedStyles : IStyleFunctionOrObject < ICheckboxStyleProps , ICheckboxStyles > = { root : { pointerEvents : 'none' } } ;
228
+ if ( isSelected || childIsSelected ) {
229
+ selectedStyles . label = { fontWeight : 'bold' } ;
230
+ }
231
+ else {
232
+ selectedStyles . label = { fontWeight : 'normal' } ;
233
+ }
229
234
230
235
return (
231
- < Checkbox
232
- key = { groupHeaderProps . group . key }
233
- label = { groupHeaderProps . group . name }
234
- onChange = { ( ev ?: React . FormEvent < HTMLElement | HTMLInputElement > , checked ?: boolean ) =>
235
- onCheckboxChange ( ev , checked , { name : groupHeaderProps . group . name , key : groupHeaderProps . group . key } ) }
236
- checked = { isSelected }
237
- styles = { selectedStyles }
238
- disabled = { groupHeaderProps . group . data . term . isAvailableForTagging . filter ( ( t ) => t . setId === props . termSetId . toString ( ) ) [ 0 ] . isAvailable === false }
239
- onRenderLabel = { ( p ) => < span className = { css ( styles . checkbox , isSelected && styles . selectedCheckbox ) } title = { p . title } >
240
- { p . label }
241
- </ span > }
242
- / >
236
+ < div { ... selectionProps } >
237
+ < Checkbox
238
+ key = { groupHeaderProps . group . key }
239
+ label = { groupHeaderProps . group . name }
240
+ checked = { isSelected }
241
+ styles = { selectedStyles }
242
+ disabled = { isDisabled }
243
+ onRenderLabel = { ( p ) => < span className = { css ( styles . checkbox , isSelected && styles . selectedCheckbox ) } title = { p . title } >
244
+ { p . label }
245
+ </ span > }
246
+ />
247
+ </ div >
243
248
) ;
244
249
}
245
250
else {
246
- const isSelected = selection . isKeySelected ( groupHeaderProps . group . key ) ;
247
- const selectedStyle : IStyleFunctionOrObject < IChoiceGroupOptionStyleProps , IChoiceGroupOptionStyles > = isSelected || isBold ? { root : { marginTop : 0 } , choiceFieldWrapper : { fontWeight : 'bold' , } } : { root : { marginTop : 0 } , choiceFieldWrapper : { fontWeight : 'normal' } } ;
248
- const isDisabled = groupHeaderProps . group . data . term . isAvailableForTagging . filter ( ( t ) => t . setId === props . termSetId . toString ( ) ) [ 0 ] . isAvailable === false ;
251
+ const selectedStyle : IStyleFunctionOrObject < IChoiceGroupOptionStyleProps , IChoiceGroupOptionStyles > = isSelected || childIsSelected ? { root : { marginTop : 0 } , choiceFieldWrapper : { fontWeight : 'bold' , } } : { root : { marginTop : 0 } , choiceFieldWrapper : { fontWeight : 'normal' } } ;
249
252
const options : IChoiceGroupOption [ ] = [ {
250
253
key : groupHeaderProps . group . key ,
251
254
text : groupHeaderProps . group . name ,
@@ -256,13 +259,21 @@ export function TaxonomyPanelContents(props: ITaxonomyFormProps): React.ReactEle
256
259
</ span >
257
260
} ] ;
258
261
262
+ if ( isDisabled ) {
263
+ selectionProps [ "data-selection-disabled" ] = true ;
264
+ }
265
+ else {
266
+ selectionProps [ "data-selection-select" ] = true ;
267
+ }
268
+
259
269
return (
260
- < ChoiceGroup
261
- options = { options }
262
- selectedKey = { selection . getSelection ( ) [ 0 ] ?. key }
263
- onChange = { onChoiceChange }
264
- disabled = { isDisabled }
265
- />
270
+ < div { ...selectionProps } >
271
+ < ChoiceGroup
272
+ options = { options }
273
+ selectedKey = { selection . getSelection ( ) [ 0 ] ?. key }
274
+ disabled = { isDisabled }
275
+ />
276
+ </ div >
266
277
) ;
267
278
}
268
279
} ;
@@ -376,7 +387,7 @@ export function TaxonomyPanelContents(props: ITaxonomyFormProps): React.ReactEle
376
387
const tagPickerStyles : IStyleFunctionOrObject < IBasePickerStyleProps , IBasePickerStyles > = { root : { paddingTop : 4 , paddingBottom : 4 , paddingRight : 4 , minheight : 34 } , input : { minheight : 34 } , text : { minheight : 34 , borderStyle : 'none' , borderWidth : '0px' } } ;
377
388
378
389
return (
379
- < div className = { styles . taxonomyForm } >
390
+ < div className = { styles . taxonomyPanelContents } >
380
391
< div className = { styles . taxonomyTreeSelector } >
381
392
< div >
382
393
< TagPicker
@@ -396,13 +407,18 @@ export function TaxonomyPanelContents(props: ITaxonomyFormProps): React.ReactEle
396
407
</ div >
397
408
< Label className = { styles . taxonomyTreeLabel } > { strings . ModernTaxonomyPickerTreeTitle } </ Label >
398
409
< div >
399
- < GroupedList
400
- items = { [ ] }
401
- onRenderCell = { null }
402
- groups = { groups }
403
- groupProps = { groupProps }
404
- onShouldVirtualize = { ( p : IListProps < any > ) => false }
405
- />
410
+ < SelectionZone
411
+ selectionMode = { props . allowMultipleSelections ? SelectionMode . multiple : SelectionMode . single }
412
+ selection = { selection }
413
+ >
414
+ < GroupedList
415
+ items = { [ ] }
416
+ onRenderCell = { null }
417
+ groups = { groups }
418
+ groupProps = { groupProps }
419
+ onShouldVirtualize = { ( p : IListProps < any > ) => false }
420
+ />
421
+ </ SelectionZone >
406
422
</ div >
407
423
</ div >
408
424
) ;
0 commit comments