@@ -20,6 +20,7 @@ import {
2020 TextField ,
2121 type TextFieldProps ,
2222 createFilterOptions ,
23+ major as muiMajor ,
2324 useForkRef ,
2425} from '@mui/material' ;
2526import {
@@ -632,6 +633,32 @@ If you provided a React element for the optionText prop, you must also provide t
632633 return offline ;
633634 }
634635
636+ const renderChips = ( value , getProps : ( args : { index : number } ) => any ) =>
637+ value . map ( ( option , index ) => {
638+ // We have to extract the key because react 19 does not allow to spread the key prop
639+ const { key, ...chipProps } = getProps ( { index } ) ;
640+ // @ts -expect-error slotProps do not yet exist in MUI v5
641+ const mergedSlotProps = props . slotProps ?. chip
642+ ? // @ts -expect-error slotProps do not yet exist in MUI v5
643+ props . slotProps . chip
644+ : props . ChipProps ;
645+ return (
646+ < Chip
647+ label = {
648+ isValidElement ( optionText )
649+ ? inputText
650+ ? inputText ( option )
651+ : ''
652+ : getChoiceText ( option )
653+ }
654+ size = "small"
655+ key = { key }
656+ { ...chipProps }
657+ { ...mergedSlotProps }
658+ />
659+ ) ;
660+ } ) ;
661+
635662 const finalLoadingText =
636663 typeof loadingText === 'string'
637664 ? translate ( loadingText , {
@@ -720,32 +747,9 @@ If you provided a React element for the optionText prop, you must also provide t
720747 ) ;
721748 } }
722749 multiple = { multiple }
723- renderTags = { ( value , getTagProps ) =>
724- value . map ( ( option , index ) => {
725- // We have to extract the key because react 19 does not allow to spread the key prop
726- const { key, ...tagProps } = getTagProps ( { index } ) ;
727- // @ts -expect-error slotProps do not yet exist in MUI v5
728- const mergedSlotProps = props . slotProps ?. chip
729- ? // @ts -expect-error slotProps do not yet exist in MUI v5
730- props . slotProps . chip
731- : props . ChipProps ;
732- return (
733- < Chip
734- label = {
735- isValidElement ( optionText )
736- ? inputText
737- ? inputText ( option )
738- : ''
739- : getChoiceText ( option )
740- }
741- size = "small"
742- key = { key }
743- { ...tagProps }
744- { ...mergedSlotProps }
745- />
746- ) ;
747- } )
748- }
750+ { ...( muiMajor >= 7
751+ ? { renderValue : renderChips }
752+ : { renderTags : renderChips } ) }
749753 noOptionsText = {
750754 typeof noOptionsText === 'string'
751755 ? translate ( noOptionsText , { _ : noOptionsText } )
0 commit comments