javascript - 如何在菜单项中显示内联图标?
问题描述
问题
这是我选择后的选择菜单。问题是图标(对话气泡内的问号)出现在与文本(“问题”)不同的行上。
图 1. 选择后的菜单。图标和文字是 display:block;目标
我希望选择后的样式是内联显示。类似于菜单显示选项预选的方式。
图 2. 打开菜单预选。图标和文字是 display:inline;代码
这是代码。
const typeConfig = [
{ value : 'bug' , label : 'Bug report' , icon : 'bug_report' , } ,
{ value : 'positive' , label : 'Positive review' , icon : 'thumb_up' , } ,
{ value : 'negative' , label : 'Negative review' , icon : 'thumb_down' , } ,
{ value : 'question' , label : 'Question' , icon : 'contact_support' , } ,
{ value : 'comment' , label : 'Comment' , icon : 'comment' , } ,
{ value : 'suggestion' , label : 'Suggestion' , icon : 'feedback' , } ,
{ value : 'request' , label : 'Feature request' , icon : 'touch_app' , } ,
]
<FormControl variant="outlined" fullWidth>
<InputLabel ref={inputLabel} htmlFor="select">{typeLabel}</InputLabel>
<Select
value={type}
onChange={handleChangeType}
input={<OutlinedInput labelWidth={labelWidth} name="select" id="select" />}
>
{
typeConfig.map( item =>
<MenuItem key={item.value} value={item.value}>
<ListItemIcon>
<Icon>{item.icon}</Icon>
</ListItemIcon>
<Typography variant="inherit" display="inline" noWrap>{item.label}</Typography>
</MenuItem>
)}
</Select>
</FormControl>
解决方案
评论摘要
我正在使用顺风。所以我成功添加了inline
如下样式。
<ListItemIcon className="inline">
<Icon>{item.icon}</Icon>
</ListItemIcon>
<Typography className="inline" variant="inherit" display="inline" noWrap>
{item.label}
</Typography>
推荐阅读
- c - 为什么控制台在将消息写入文件描述符0 1 2时显示消息
- string - 使用 Grep 拉线,同时省略重复的字符串
- r - 如何从 R 中的数据框中删除带有 inf 的行?
- virtualhost - 使用 HTTP/2 时如何在 Cro 中获取 Host 或 :authority 标头
- javascript - jQuery:在 keydown 上的两个单选按钮之间切换
- python - Python ValueError:没有足够的值来解包(预期 3,得到 2)
- python - 如何解压缩嵌套字典,其中并非每个顶级键都具有所有二级键?
- html - 如何使用该文件将项目永久添加到 HTML 文件中的列表
- python-3.x - 如何执行两个不同pdf文档的关键字匹配分数?
- ios - 表视图不调用 cellForRowAt