我有一个相当简单的 react 组件:
<Quantity type="number" value="1"></Quantity>
使用 StyledComponents 进行样式化,如下所示:
const Quantity = styled.input`
border: 1px solid #000;
border-radius: 2px;
width: 48px;
height: 28px;
font-size: 18px;
text-align: center;
margin-right: 10px
`;
现在看起来像这样:
我想让它看起来像这样:
谢谢!
最佳答案
您可以做的是隐藏默认的增量器按钮并创建自己的按钮来增加和减少状态值。
const Quantity = styled.input`
border: 1px solid #000;
border-radius: 2px;
width: 48px;
height: 28px;
font-size: 18px;
text-align: center;
margin-right: 10px
//hide the default button
&::-webkit-appearance: textfield;
&::-moz-appearance: textfield;
appearance: textfield;
&::-webkit-inner-spin-button,
&::-webkit-outer-spin-button
&::-webkit-appearance: none;
`;
const Incrementer = styled.button`
...
`;
const Decrementer = styled.button`
...
`;
...
const [inputValue, setInputValue] = useState(0);
...
<Incrementer onClick={() => setInputValue(inputValue + 1)} />
<Quantity value={inputValue}/>
<Decrementer onClick={() => setInputValue(inputValue - 1)} />
关于javascript - 输入[数字]箭头超出输入区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56473503/