gpt4 book ai didi

javascript - 输入[数字]箭头超出输入区域

转载 作者:行者123 更新时间:2023-12-02 23:31:39 26 4
gpt4 key购买 nike

我有一个相当简单的 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
`;

现在看起来像这样:

enter image description here

我想让它看起来像这样:

enter image description here

谢谢!

最佳答案

您可以做的是隐藏默认的增量器按钮并创建自己的按钮来增加和减少状态值。

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com