@@ -89,10 +89,12 @@ export const Combobox = forwardRef<HTMLDivElement, IComboboxProps>(
8989 const tagProps : Record < string , IOptionProps [ 'tagProps' ] > = { } ;
9090 const retVal = toOptions ( children , tagProps ) ;
9191
92- setOptionTagProps ( value => ( { ...value , ...tagProps } ) ) ;
92+ if ( isMultiselectable ) {
93+ setOptionTagProps ( value => ( { ...value , ...tagProps } ) ) ;
94+ }
9395
9496 return retVal ;
95- } , [ children ] ) ;
97+ } , [ children , isMultiselectable ] ) ;
9698 const hasFocus = useRef ( false ) ;
9799 const triggerRef = useRef < HTMLDivElement > ( null ) ;
98100 const inputRef = useRef < HTMLInputElement > ( null ) ;
@@ -213,6 +215,21 @@ export const Combobox = forwardRef<HTMLDivElement, IComboboxProps>(
213215 return ( ) => labelProps && setLabelProps ( undefined ) ;
214216 } , [ getLabelProps , labelProps , setLabelProps ] ) ;
215217
218+ useEffect ( ( ) => {
219+ // prevent `optionTagProps` state bloat
220+ if ( Array . isArray ( selection ) ) {
221+ setOptionTagProps ( values =>
222+ selection . reduce ( ( value , option ) => {
223+ const key = toString ( option ) ;
224+
225+ return { ...value , [ key ] : values [ key ] } ;
226+ } , { } )
227+ ) ;
228+ }
229+
230+ return ( ) => setOptionTagProps ( { } ) ;
231+ } , [ selection ] ) ;
232+
216233 const Tags = ( { selectedOptions } : { selectedOptions : IOption [ ] } ) => {
217234 const [ isFocused , setIsFocused ] = useState ( hasFocus . current ) ;
218235 const value = selectedOptions . length - maxTags ;
0 commit comments