@@ -26,7 +26,6 @@ export interface IModernTaxonomyPickerProps {
26
26
label : string ;
27
27
context : BaseComponentContext ;
28
28
initialValues ?: ITag [ ] ;
29
- errorMessage ?: string ; // TODO: is this needed?
30
29
disabled ?: boolean ;
31
30
required ?: boolean ;
32
31
onChange ?: ( newValue ?: ITag [ ] ) => void ;
@@ -35,38 +34,30 @@ export interface IModernTaxonomyPickerProps {
35
34
36
35
export function ModernTaxonomyPicker ( props : IModernTaxonomyPickerProps ) {
37
36
const [ termsService ] = React . useState ( ( ) => new SPTaxonomyService ( props . context ) ) ;
38
- const [ errorMessage , setErrorMessage ] = React . useState ( props . errorMessage ) ;
39
- const [ internalErrorMessage , setInternalErrorMessage ] = React . useState < string > ( ) ;
40
37
const [ panelIsOpen , setPanelIsOpen ] = React . useState ( false ) ;
41
- const [ selectedOptions , setSelectedOptions ] = React . useState < ITag [ ] > ( [ ] ) ;
38
+ const [ selectedOptions , setSelectedOptions ] = React . useState < ITag [ ] > ( Object . prototype . toString . call ( props . initialValues ) === '[object Array]' ? props . initialValues : [ ] ) ;
42
39
const [ selectedPanelOptions , setSelectedPanelOptions ] = React . useState < ITag [ ] > ( [ ] ) ;
43
40
44
- const invalidTerm = React . useRef < string > ( null ) ;
45
-
46
41
React . useEffect ( ( ) => {
47
42
sp . setup ( props . context ) ;
48
43
} , [ ] ) ;
49
44
50
- React . useEffect ( ( ) => {
51
- if ( Object . prototype . toString . call ( props . initialValues ) === '[object Array]' ) {
52
- setSelectedOptions ( props . initialValues ) ;
53
- }
54
- else {
55
- setSelectedOptions ( [ ] ) ;
56
- }
57
- } , [ props . initialValues ] ) ;
58
-
59
- React . useEffect ( ( ) => {
60
- setErrorMessage ( props . errorMessage ) ;
61
- } , [ props . errorMessage ] ) ;
45
+ // React.useEffect(() => {
46
+ // if(Object.prototype.toString.call(props.initialValues) === '[object Array]' ) {
47
+ // setSelectedOptions(props.initialValues);
48
+ // }
49
+ // else {
50
+ // setSelectedOptions([]);
51
+ // }
52
+ // }, []);
62
53
63
54
React . useEffect ( ( ) => {
64
55
if ( props . onChange ) {
65
56
props . onChange ( selectedOptions ) ;
66
57
}
67
58
} , [ selectedOptions ] ) ;
68
59
69
- async function onOpenPanel ( ) : Promise < void > {
60
+ function onOpenPanel ( ) : void {
70
61
if ( props . disabled === true ) {
71
62
return ;
72
63
}
@@ -108,30 +99,30 @@ export function ModernTaxonomyPicker(props: IModernTaxonomyPickerProps) {
108
99
return filteredTags ;
109
100
}
110
101
111
- const { label, disabled, allowMultipleSelections, panelTitle, required, placeHolder } = props ;
112
102
const calloutProps = { gapSpace : 0 } ;
113
103
const tooltipId = useId ( 'tooltip' ) ;
114
104
const hostStyles : Partial < ITooltipHostStyles > = { root : { display : 'inline-block' } } ;
105
+ const addTermButtonStyles : IButtonStyles = { rootHovered : { backgroundColor : "inherit" } , rootPressed : { backgroundColor : "inherit" } } ;
115
106
116
107
return (
117
108
< div className = { styles . modernTaxonomyPicker } >
118
- { label && < Label required = { required } > { label } </ Label > }
109
+ { props . label && < Label required = { props . required } > { props . label } </ Label > }
119
110
< div className = { styles . termField } >
120
111
< div className = { styles . termFieldInput } >
121
112
< TagPicker
122
113
removeButtonAriaLabel = { strings . ModernTaxonomyPickerRemoveButtonText }
123
114
onResolveSuggestions = { onResolveSuggestions }
124
- itemLimit = { allowMultipleSelections ? undefined : 1 }
115
+ itemLimit = { props . allowMultipleSelections ? undefined : 1 }
125
116
selectedItems = { selectedOptions }
126
- disabled = { disabled }
117
+ disabled = { props . disabled }
127
118
onChange = { ( itms ?: ITag [ ] ) => {
128
119
setSelectedOptions ( itms || [ ] ) ;
129
120
setSelectedPanelOptions ( itms || [ ] ) ;
130
121
} }
131
- getTextFromItem = { ( tag : ITag , currentValue ?: string ) => tag . name }
122
+ getTextFromItem = { ( tag : ITag ) => tag . name }
132
123
inputProps = { {
133
- 'aria-label' : placeHolder || strings . ModernTaxonomyPickerDefaultPlaceHolder ,
134
- placeholder : placeHolder || strings . ModernTaxonomyPickerDefaultPlaceHolder
124
+ 'aria-label' : props . placeHolder || strings . ModernTaxonomyPickerDefaultPlaceHolder ,
125
+ placeholder : props . placeHolder || strings . ModernTaxonomyPickerDefaultPlaceHolder
135
126
} }
136
127
/>
137
128
</ div >
@@ -142,20 +133,18 @@ export function ModernTaxonomyPicker(props: IModernTaxonomyPickerProps) {
142
133
calloutProps = { calloutProps }
143
134
styles = { hostStyles }
144
135
>
145
- < IconButton disabled = { disabled } iconProps = { { iconName : 'Tag' } as IIconProps } onClick = { onOpenPanel } aria-describedby = { tooltipId } />
136
+ < IconButton disabled = { props . disabled } styles = { addTermButtonStyles } iconProps = { { iconName : 'Tag' } as IIconProps } onClick = { onOpenPanel } aria-describedby = { tooltipId } />
146
137
</ TooltipHost >
147
138
</ div >
148
139
</ div >
149
140
150
- < FieldErrorMessage errorMessage = { errorMessage || internalErrorMessage } />
151
-
152
141
< Panel
153
142
isOpen = { panelIsOpen }
154
143
hasCloseButton = { true }
155
144
onDismiss = { onClosePanel }
156
145
isLightDismiss = { true }
157
146
type = { PanelType . medium }
158
- headerText = { panelTitle }
147
+ headerText = { props . panelTitle }
159
148
onRenderFooterContent = { ( ) => {
160
149
const horizontalGapStackTokens : IStackTokens = {
161
150
childrenGap : 10 ,
@@ -172,7 +161,7 @@ export function ModernTaxonomyPicker(props: IModernTaxonomyPickerProps) {
172
161
props . termSetId && (
173
162
< div key = { props . termSetId } >
174
163
< TaxonomyForm
175
- allowMultipleSelections = { allowMultipleSelections }
164
+ allowMultipleSelections = { props . allowMultipleSelections }
176
165
onResolveSuggestions = { onResolveSuggestions }
177
166
onLoadMoreData = { termsService . getTerms }
178
167
getTermSetInfo = { termsService . getTermSetInfo }
@@ -181,7 +170,7 @@ export function ModernTaxonomyPicker(props: IModernTaxonomyPickerProps) {
181
170
pageSize = { 50 }
182
171
selectedPanelOptions = { selectedPanelOptions }
183
172
setSelectedPanelOptions = { setSelectedPanelOptions }
184
- placeHolder = { placeHolder || strings . ModernTaxonomyPickerDefaultPlaceHolder }
173
+ placeHolder = { props . placeHolder || strings . ModernTaxonomyPickerDefaultPlaceHolder }
185
174
/>
186
175
</ div >
187
176
)
0 commit comments