Skip to content

Commit e092701

Browse files
Changed selection method and some styling
1 parent 1c00c21 commit e092701

File tree

2 files changed

+65
-55
lines changed

2 files changed

+65
-55
lines changed

src/controls/modernTaxonomyPicker/taxonomyPanelContents/TaxonomyPanelContents.module.scss

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
@import '~office-ui-fabric-react/dist/sass/References.scss';
22

3-
.taxonomyForm {
4-
.container {
5-
max-width: 700px;
6-
margin: 0px auto;
7-
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
8-
}
9-
3+
.taxonomyPanelContents {
104
.choiceOption {
115
color: "[theme: bodyText, default: #323130]";
126
padding-left: 26px;

src/controls/modernTaxonomyPicker/taxonomyPanelContents/TaxonomyPanelContents.tsx

Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
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';
44
import { ITermInfo, ITermSetInfo, ITermStoreInfo } from '@pnp/sp/taxonomy';
55
import { Guid } from '@microsoft/sp-core-library';
66
import { BaseComponentContext } from '@microsoft/sp-component-base';
@@ -194,58 +194,61 @@ export function TaxonomyPanelContents(props: ITaxonomyFormProps): React.ReactEle
194194
}
195195
};
196196

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-
211197
const onRenderTitle = (groupHeaderProps: IGroupHeaderProps) => {
212198
const isChildSelected = (children: IGroup[]): boolean => {
213199
let aChildIsSelected = children && children.some((child) => selection.isKeySelected(child.key) || isChildSelected(child.children));
214200
return aChildIsSelected;
215201
};
216202

217-
const isBold = isChildSelected(groupHeaderProps.group.children);
203+
const childIsSelected = isChildSelected(groupHeaderProps.group.children);
218204

219205
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"}};
221207
return (
222208
<Label styles={labelStyles}>{groupHeaderProps.group.name}</Label>
223209
);
224210
}
225211

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+
226219
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+
}
229234

230235
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>
243248
);
244249
}
245250
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' } };
249252
const options: IChoiceGroupOption[] = [{
250253
key: groupHeaderProps.group.key,
251254
text: groupHeaderProps.group.name,
@@ -256,13 +259,21 @@ export function TaxonomyPanelContents(props: ITaxonomyFormProps): React.ReactEle
256259
</span>
257260
}];
258261

262+
if (isDisabled) {
263+
selectionProps["data-selection-disabled"] = true;
264+
}
265+
else {
266+
selectionProps["data-selection-select"] = true;
267+
}
268+
259269
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>
266277
);
267278
}
268279
};
@@ -376,7 +387,7 @@ export function TaxonomyPanelContents(props: ITaxonomyFormProps): React.ReactEle
376387
const tagPickerStyles: IStyleFunctionOrObject<IBasePickerStyleProps, IBasePickerStyles> = { root: {paddingTop: 4, paddingBottom: 4, paddingRight: 4, minheight: 34}, input: {minheight: 34}, text: { minheight: 34, borderStyle: 'none', borderWidth: '0px' } };
377388

378389
return (
379-
<div className={styles.taxonomyForm}>
390+
<div className={styles.taxonomyPanelContents}>
380391
<div className={styles.taxonomyTreeSelector}>
381392
<div>
382393
<TagPicker
@@ -396,13 +407,18 @@ export function TaxonomyPanelContents(props: ITaxonomyFormProps): React.ReactEle
396407
</div>
397408
<Label className={styles.taxonomyTreeLabel}>{strings.ModernTaxonomyPickerTreeTitle}</Label>
398409
<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>
406422
</div>
407423
</div>
408424
);

0 commit comments

Comments
 (0)