I have a a dropdown component that allows user to select the language they desired. When the item is selected, the image and the text should be displayed in a row. The problem is that the selected item is displayed vertically. I tried using flexDirection: 'row'
on the Select
component and MenuItem
component, but it didnt work.
<Box sx={{width: '100%'}}>
<Select sx={{width: '160px'}} defaultValue={1}>
<MenuItem sx={{gap: 1}} value={1}>
<Avatar src={UK} sx={{width: 24, height: 24 }}/>
English
</MenuItem>
<MenuItem sx={{gap: 1}} value={2}>
<Avatar src={Malaysia} sx={{width: 24, height: 24 }}/>
Malay
</MenuItem>
<MenuItem sx={{gap: 1}} value={3}>
<Avatar src={China} sx={{width: 24, height: 24 }}/>
Mandarin
</MenuItem>
</Select>
</Box>
2
Answers
you need to use Stack for the same.
Here, is the full code:
Let me know, if you have any questios.
I added display: ‘flex’ and flexDirection: ‘row’ to the MenuItem components to make sure they are displayed horizontally. The Box component with display: ‘flex’ is used to wrap the MenuItem elements.
Let me know, if you have any questions.