Skip to content
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

Closed
wants to merge 7 commits into from
Closed

feat: support max length #313

wants to merge 7 commits into from

Conversation

hengkx
Copy link
Member

@hengkx hengkx commented Apr 7, 2021

close #311

@hengkx hengkx requested a review from zombieJ April 7, 2021 02:41
@vercel
Copy link

vercel bot commented Apr 7, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/react-component/input-number/BSk7kabHAJHYj8812gYYqvizA2iD
✅ Preview: https://input-number-git-maxlength-react-component.vercel.app

@yoyo837
Copy link
Member

yoyo837 commented Apr 7, 2021

个人拙见,input-number基本属于 maxlength无关的组件。

@codecov
Copy link

codecov bot commented Apr 7, 2021

Codecov Report

Merging #313 (427d533) into master (99cb077) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head 427d533 differs from pull request most recent head 76d2bf8. Consider uploading reports for the commit 76d2bf8 to get more accurate results
Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
src/InputNumber.tsx 98.19% <100.00%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 99cb077...76d2bf8. Read the comment docs.

@hengkx
Copy link
Member Author

hengkx commented Apr 7, 2021

产品需求 就是 输入到 最大后 用户 不能再输入了

@yoyo837
Copy link
Member

yoyo837 commented Apr 7, 2021

我的意思是input-number应该min,max控制是不是就足够了?

另外如果支持两位小数,手动输入时,maxlength会不会对100.00100 造成影响?

@afc163
Copy link
Member

afc163 commented Apr 7, 2021

透传原生 maxLength 够用了吧。

@hengkx
Copy link
Member Author

hengkx commented Apr 7, 2021

我的意思是input-number应该min,max控制是不是就足够了?

另外如果支持两位小数,手动输入时,maxlength会不会对100.00100 造成影响?

min,max 是输入到最大后 可以继续输入,鼠标离开后 会重置成最大,maxlength 会对 100.00100 造成影响

@hengkx
Copy link
Member Author

hengkx commented Apr 7, 2021

我的意思是input-number应该min,max控制是不是就足够了?
另外如果支持两位小数,手动输入时,maxlength会不会对100.00100 造成影响?

min,max 是输入到最大后 可以继续输入,鼠标离开后 会重置成最大,maxlength 会对 100.00100 造成影响

因为 这些 属性 都是用户 自己 设置的,他可以根据他的实际情况 以及需求来做设置

@yoyo837
Copy link
Member

yoyo837 commented Apr 7, 2021

所以maxlength和min、max有冲突,按什么逻辑处理?

@hengkx
Copy link
Member Author

hengkx commented Apr 7, 2021

透传原生 maxLength 够用了吧。

好像是有问题的,我们之前的代码是 重写了onInput 方法,这边的改动 导致 该方法 不兼容了

@yoyo837
Copy link
Member

yoyo837 commented Apr 7, 2021

反过来,部分用户会不会理解为遵循maxlength 而min max用户根据他的实际情况 以及需求来做设置呢?

感觉会造成很多Q&A issue。

@hengkx
Copy link
Member Author

hengkx commented Apr 7, 2021

所以maxlength和min、max有冲突,按什么逻辑处理?

现在的改动是 超出maxlength后直接截取字符串 然后 在走后面的逻辑

let inputStr = e.target.value;
if (maxLength) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

来个测试用例哈~

let inputStr = e.target.value;
if (maxLength) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (maxLength) {
if (maxLength >= 0) {

这样会不会好些?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不太对哦,是不是 大于0 就行了 等于 没有任何意义吧

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不太对哦,是不是 大于0 就行了 等于 没有任何意义吧

主要目的是为了判断为数字

@@ -80,6 +80,11 @@ describe('InputNumber.Input', () => {
expect(wrapper.getInputValue()).toEqual('');
});

it('max length', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

再加一个0的?

});

it('control max length', () => {
const wrapper = mount(<InputNumber value={9} maxLength={3} />);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value={1234},它的长度需要超过 maxLength,且结果是 1234 不会被裁剪。

Copy link
Member Author

@hengkx hengkx Apr 13, 2021

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zombieJ
Copy link
Member

zombieJ commented Apr 13, 2021

LGTM,先等一下这个 #316。好了后发个 minor。

@afc163
Copy link
Member

afc163 commented Apr 13, 2021

为啥不是直接透传 maxLength 给原生 input 元素呢?

@zombieJ
Copy link
Member

zombieJ commented Apr 13, 2021

为啥不是直接透传 maxLength 给原生 input 元素呢?

format 可以改输入内容,用户输入不一定是最终展示值。

@afc163
Copy link
Member

afc163 commented Apr 13, 2021

那原生 maxLength 也够用了吧,设置不超过 format 后的长度就行。

@AngelPP52
Copy link

我也有一样的想法,但老兄这里要把键盘事件/step事件也考虑上吧?

@hengkx hengkx closed this Sep 10, 2021
@hengkx hengkx deleted the maxLength branch September 10, 2021 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

增加 maxLength 属性,输入最大长度后不能继续输入
5 participants