[英]Need to align and style MUI icon button & text input
I have designed a modal dialog that uses increment & decrement buttons on text-input values.我设计了一个模式对话框,在文本输入值上使用增量和减量按钮。 I need to align and put some style to it.我需要对齐并为其添加一些样式。 as per the image it's not really looking good.根据图像,它看起来并不好。 anyway, it does the functions.无论如何,它的功能。
I want something like this for adult tickets I don't need +/- buttons我想要这样的成人票我不需要 +/- 按钮 Code代码
<ul>
<li>
Adult Tickets
<TextField
value={AdSeatCount}
id="outlined-adornment-small-Adult"
variant="outlined"
size="small"
style={{ width: 48, height: 35}}
labelWidth={0}
disabled="true"
/>
<br/>
</li>
<li>Child Tickets
<div style={{ display: "flex", alignItems: "center" }}>
<IconButton
onClick={this.onMinusClick}
aria-label="minus"
style={{ marginTop: 15 }}
>
<RemoveCircleIcon fontSize="inherit" />
</IconButton>
<TextField
value={this.state.value}
id="outlined-adornment-small-Child"
variant="outlined"
size="small"
style={{ width: 48, height: 35 ,marginTop: 15}}
labelWidth={0}
disabled="true"
/>
<IconButton
onClick={this.onPlusClick}
aria-label="plus"
style={{ marginTop: 15 }}
>
<AddCircleIcon fontSize="inherit" />
</IconButton>
</div>
</li>
</ul>
[1]: https://i.stack.imgur.com/YQQYf.png
Wrap the IconButtons
and the TextField
in a flexbox div, as follows.将IconButtons
和TextField
包装在flexbox div 中,如下所示。
<div style={{ display: "flex", alignItems: "center" }}>
<IconButton
onClick={this.onMinusClick}
aria-label="minus"
style={{ marginTop: 15 }}
>
<RemoveCircleIcon fontSize="inherit" />
</IconButton>
<TextField
value={this.state.value}
id="outlined-adornment-small-Child"
variant="outlined"
size="small"
style={{ width: 48, height: 35, marginTop: 15 }}
labelWidth={0}
disabled="true"
/>
<IconButton
onClick={this.onPlusClick}
aria-label="plus"
style={{ marginTop: 15 }}
>
<AddCircleIcon fontSize="inherit" />
</IconButton>
</div>
The easiest way is to use the Stack component that gives you out of the box all the attributes you need to have the desired result.最简单的方法是使用 Stack 组件,它可以为您提供开箱即用的所有属性,以获得所需的结果。
In this codesandbox is your solution, (I had to replace some of the state stuff for the values.) Please note that I also had to remove some of the css you has added as it was wrong.在此代码框中是您的解决方案,(我必须替换一些值的状态内容。)请注意,我还必须删除您添加的一些 css,因为它是错误的。
Here is you refactored code, note that you had to import the Stack
component这是您重构的代码,请注意您必须导入Stack
组件
import Stack from "@mui/material/Stack";
<ul>
<li>
<Stack
direction="row"
justifyContent="flex-start"
alignItems="center"
spacing={1}
my={2}
>
Adult Tickets
<TextField
value={AdSeatCount}
id="outlined-adornment-small-Adult"
variant="outlined"
size="small"
style={{ width: 48 }}
labelWidth={0}
disabled="true"
/>
</Stack>
</li>
<li>
<Stack
direction="row"
justifyContent="flex-start"
alignItems="center"
spacing={1}
my={2}
>
Child Tickets
<IconButton
onClick={this.onMinusClick}
aria-label="minus"
>
<RemoveCircleIcon fontSize="inherit" />
</IconButton>
<TextField
value={this.state.value}
id="outlined-adornment-small-Child"
variant="outlined"
size="small"
style={{ width: 48}}
labelWidth={0}
disabled="true"
/>
<IconButton
onClick={this.onPlusClick}
aria-label="plus"
>
<AddCircleIcon fontSize="inherit" />
</IconButton>
</Stack>
</li>
</ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.