-
-
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
Feature/新增非法输入警告 #409
Open
huangminjianxx
wants to merge
5
commits into
react-component:master
Choose a base branch
from
huangminjianxx:feature/新增非法输入警告
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "feature/\u65B0\u589E\u975E\u6CD5\u8F93\u5165\u8B66\u544A"
Open
Feature/新增非法输入警告 #409
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,6 +139,8 @@ const InputNumber = React.forwardRef( | |
|
||
const [focus, setFocus] = React.useState(false); | ||
|
||
const [illegalData, setIllegalData] = React.useState(false); | ||
|
||
const userTypingRef = React.useRef(false); | ||
const compositionRef = React.useRef(false); | ||
|
||
|
@@ -399,8 +401,17 @@ const InputNumber = React.forwardRef( | |
collectInputValue(inputRef.current.value); | ||
}; | ||
|
||
const judgeData = (inputNumberValue: string) => { | ||
if(isNaN(Number(inputNumberValue)) || (max && inputNumberValue > max) || (min && inputNumberValue < min)){ | ||
return true | ||
}else{ | ||
return false | ||
} | ||
} | ||
|
||
// >>> Input | ||
const onInternalInput: React.ChangeEventHandler<HTMLInputElement> = (e) => { | ||
setIllegalData(judgeData(e.target.value)) | ||
collectInputValue(e.target.value); | ||
}; | ||
|
||
|
@@ -487,6 +498,8 @@ const InputNumber = React.forwardRef( | |
// >>> Focus & Blur | ||
const onBlur = () => { | ||
flushInputValue(false); | ||
|
||
setIllegalData(false) | ||
|
||
setFocus(false); | ||
|
||
|
@@ -531,7 +544,7 @@ const InputNumber = React.forwardRef( | |
[`${prefixCls}-disabled`]: disabled, | ||
[`${prefixCls}-readonly`]: readOnly, | ||
[`${prefixCls}-not-a-number`]: decimalValue.isNaN(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 非数字其实应该在此处判断,更符合语义,不过这个 css 类名没写样式。需要在 |
||
[`${prefixCls}-out-of-range`]: !decimalValue.isInvalidate() && !isInRange(decimalValue), | ||
[`${prefixCls}-out-of-range`]: (!decimalValue.isInvalidate() && !isInRange(decimalValue)) || illegalData, | ||
})} | ||
style={style} | ||
onFocus={() => { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
感觉这个方法跟 isInvalidate isInRange 是重复的
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.
👌,我下午再更改一下提上来。
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.
isInvalidate的作用是判断是否为空或者判断该值是否是一个数字,isInRange的作用是判断输入值是否在区间范围内,貌似可以用这两个方法结合起来去取代judgeData;
但这两个方法是decimalValue的静态方法,在用户输入的时候,decimalValue拿不到最新的值,比如原本输入框是5,我再输入一个5,在input的onChange事件中,decimalValue的拿到的值是5而不是55,这一点你觉得有什么比较好的解决方法吗?
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.
可以用 inputValue,那个是实时的。