11import React , { useState } from "react" ;
2- import { colors , ListItemIcon , ListItemText , MenuItem , Select } from "@mui/material" ;
2+ import { ListItemText , MenuItem , Select } from "@mui/material" ;
33import KeyboardDoubleArrowDownRoundedIcon from "@mui/icons-material/KeyboardDoubleArrowDownRounded" ;
44import { ImageDropdownProps } from "../utilities/interfaces/ImageDropdownProps" ;
55
@@ -24,25 +24,22 @@ const ImageDropDown: React.FunctionComponent<ImageDropdownProps> = (props: Image
2424 currentValue = e . target . value ;
2525 props . localStorageItemKey ? localStorage . setItem ( props . localStorageItemKey , currentValue ) : gotImageURLs = gotImageURLs /* Do nothing */ ;
2626 currentIndex = props . values . indexOf ( currentValue ) ;
27- setText ( props . texts [ currentIndex ] ) ;
27+ const currText = props . texts [ currentIndex ]
28+ setText ( currText ) ;
2829 props . imageURLs ? setImageURL ( props . imageURLs [ currentIndex ] ) : setImageURL ( "" ) ;
2930 props . colors ? setBackgroundColor ( props . colors [ currentIndex ] ) : setBackgroundColor ( currentBackgroundColor ) ;
31+ props . onSelectionChange ?.( currText , currentValue )
3032 }
3133
3234 return (
3335 < Select
3436 sx = { imageDropDownStyle ( currentBackgroundColor ) }
3537 IconComponent = { KeyboardDoubleArrowDownRoundedIcon }
3638 onChange = { handleChange }
37- value = { props . texts }
38- renderValue = { ( ) => (
39- < MenuItem sx = { menuItemStyle } value = { currentValue } >
40- < ListItemText sx = { visibleElement ( ! showImagesOnly ) } style = { { textAlign :"left" } } primary = { currentText } />
41- </ MenuItem >
42- ) }
39+ value = { currentValue }
4340 >
44- { props . texts . map ( ( value ) => (
45- < MenuItem sx = { menuItemStyle } value = { props . values [ props . texts . indexOf ( value ) ] } >
41+ { props . texts . map ( ( value , index ) => (
42+ < MenuItem key = { value } sx = { menuItemStyle } value = { props . values [ index ] } >
4643 < ListItemText sx = { visibleElement ( ! showImagesOnly ) } style = { { textAlign :"left" } } primary = { value } />
4744 </ MenuItem >
4845 ) ) }
0 commit comments