-
-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support max length #313
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/react-component/input-number/BSk7kabHAJHYj8812gYYqvizA2iD |
个人拙见,input-number基本属于 maxlength无关的组件。 |
Codecov Report
@@ Coverage Diff @@
## master #313 +/- ##
==========================================
+ Coverage 97.25% 97.27% +0.01%
==========================================
Files 8 8
Lines 401 403 +2
Branches 106 109 +3
==========================================
+ Hits 390 392 +2
Misses 11 11
Continue to review full report at Codecov.
|
产品需求 就是 输入到 最大后 用户 不能再输入了 |
我的意思是input-number应该min,max控制是不是就足够了? 另外如果支持两位小数,手动输入时,maxlength会不会对 |
透传原生 maxLength 够用了吧。 |
min,max 是输入到最大后 可以继续输入,鼠标离开后 会重置成最大,maxlength 会对 |
因为 这些 属性 都是用户 自己 设置的,他可以根据他的实际情况 以及需求来做设置 |
所以maxlength和min、max有冲突,按什么逻辑处理? |
好像是有问题的,我们之前的代码是 重写了 |
反过来,部分用户会不会理解为遵循maxlength 而min max用户根据他的实际情况 以及需求来做设置呢? 感觉会造成很多Q&A issue。 |
现在的改动是 超出maxlength后直接截取字符串 然后 在走后面的逻辑 |
src/InputNumber.tsx
Outdated
let inputStr = e.target.value; | ||
if (maxLength) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
来个测试用例哈~
src/InputNumber.tsx
Outdated
let inputStr = e.target.value; | ||
if (maxLength) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (maxLength) { | |
if (maxLength >= 0) { |
这样会不会好些?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不太对哦,是不是 大于0 就行了 等于 没有任何意义吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不太对哦,是不是 大于0 就行了 等于 没有任何意义吧
主要目的是为了判断为数字
Co-authored-by: Amumu <[email protected]>
tests/input.test.tsx
Outdated
@@ -80,6 +80,11 @@ describe('InputNumber.Input', () => { | |||
expect(wrapper.getInputValue()).toEqual(''); | |||
}); | |||
|
|||
it('max length', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
再加一个0的?
tests/input.test.tsx
Outdated
}); | ||
|
||
it('control max length', () => { | ||
const wrapper = mount(<InputNumber value={9} maxLength={3} />); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value={1234}
,它的长度需要超过 maxLength
,且结果是 1234
不会被裁剪。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value={1234}
max 是1
那它的值还是1234
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM,先等一下这个 #316。好了后发个 minor。 |
为啥不是直接透传 maxLength 给原生 input 元素呢? |
|
那原生 maxLength 也够用了吧,设置不超过 format 后的长度就行。 |
我也有一样的想法,但老兄这里要把键盘事件/step事件也考虑上吧? |
close #311