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

fix(inputNumber): correct onChange, onOverlimit event triggering timing when async & sync #2509

Merged
merged 11 commits into from
Aug 2, 2024

Conversation

Alex-huxiyang
Copy link
Collaborator

@Alex-huxiyang Alex-huxiyang commented Aug 1, 2024

  • onChange同步状态下的触发时机参考了stepper的习惯。
    不存在minmax时,随着输入而触发,而超出限制时,如max={6},input内容由3 -> 60应该触发onChange,返回的value为6。而60 -> 600不应该触发onChange,而这两种情况下都应该触发onOverlimit
  • aysnc状态下,blur时对值进行检验,onChangeonOverlimit的触发时机取决于blur时的数据前后的变化。

基于以上规则,进行了改造

  • 日常 bug 修复
  • 演示代码改进
  • TypeScript 定义更新
  • 重构
  • 代码风格优化

Summary by CodeRabbit

  • 新功能

    • 增强了 InputNumber 组件的事件处理能力,包括新的 onChangeonOverlimit 事件处理程序。
    • 实现了值的范围限制,确保输入在设定的最小值和最大值之间有效。
  • 错误修复

    • 修复了在输入超出限制时的处理逻辑,确保组件正确响应。
  • 测试

    • 新增测试用例,验证 InputNumber 组件在输入超出最大值时的行为。

Copy link

coderabbitai bot commented Aug 1, 2024

Warning

Rate limit exceeded

@Alex-huxiyang has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 16 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between aabb8b6 and 8ac32a3.

Walkthrough

此次更改主要增强了InputNumber组件的功能,特别是在事件处理和输入验证方面。新添加的onOverlimit事件处理器与输入值的上下限一起使用,提高了用户交互体验。通过记录输入变化并确保输入值在有效范围内,这些更新增强了组件的响应能力和可维护性。

Changes

文件 更改摘要
src/packages/inputnumber/__tests__/inputnumber.spec.tsx 新增测试用例以验证InputNumber在输入超出最大限制时的行为,增强测试覆盖率。
src/packages/inputnumber/inputnumber.taro.tsx 修改onOverlimit类型以支持更多事件类型,新增clampValue函数以确保值在范围内,优化事件处理。
src/packages/inputnumber/inputnumber.tsx 修改onOverlimit类型以支持更多事件类型,新增clampValuehandleValueChange函数,改善输入验证和响应能力。
src/packages/inputnumber/demos/h5/demo3.tsx overlimit函数接受事件参数,InputNumber新增onChange属性,提升组件交互性。
src/packages/inputnumber/demos/h5/demo8.tsx 新增overlimit处理函数,并更新InputNumbermax值和onOverlimit,改善用户反馈。
src/packages/inputnumber/demos/taro/demo3.tsx onChange中添加日志记录,增强组件的互动性。
src/packages/inputnumber/demos/taro/demo8.tsx 新增overlimit函数并修改onChange的超时逻辑,添加max值和onOverlimit属性。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant InputNumber
    participant Component

    User->>InputNumber: 输入值
    InputNumber->>Component: 触发onChange
    Component->>InputNumber: 记录新值
    InputNumber->>InputNumber: 检查上下限
    InputNumber->>Component: 触发onOverlimit(超出限制)
    Component->>InputNumber: 反馈信息
Loading

Possibly related issues

Poem

🐰 在数字之田跳跃,
响应如风,输入如潮。
新功能如花绽放,
交互体验更高高。
兔子欢呼,乐无穷! ✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Aug 1, 2024

Codecov Report

Attention: Patch coverage is 82.14286% with 5 lines in your changes missing coverage. Please review.

Project coverage is 83.16%. Comparing base (62809a0) to head (8ac32a3).

Files Patch % Lines
src/packages/inputnumber/inputnumber.tsx 82.14% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2509      +/-   ##
==========================================
+ Coverage   83.07%   83.16%   +0.08%     
==========================================
  Files         217      217              
  Lines       17764    17783      +19     
  Branches     2554     2564      +10     
==========================================
+ Hits        14758    14789      +31     
+ Misses       3001     2989      -12     
  Partials        5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Outside diff range, codebase verification and nitpick comments (2)
src/packages/inputnumber/inputnumber.tsx (1)

Line range hint 201-210:
代码无误,但请添加测试!

handleInputChange 函数使用 clampValue 确保影子值根据夹紧输入值一致更新。

根据静态分析工具的提示,以下代码行未覆盖测试:#L208, #L210。请添加相应的测试。

您希望我生成单元测试代码还是创建一个 GitHub issue 来跟踪此任务?

Tools
GitHub Check: codecov/patch

[warning] 208-208: src/packages/inputnumber/inputnumber.tsx#L208
Added line #L208 was not covered by tests


[warning] 210-210: src/packages/inputnumber/inputnumber.tsx#L210
Added line #L210 was not covered by tests

src/packages/inputnumber/inputnumber.taro.tsx (1)

Line range hint 201-214:
代码无误,但请添加测试!

handleInputChange 函数使用 clampValue 确保影子值根据夹紧输入值一致更新。

请添加相应的测试。

您希望我生成单元测试代码还是创建一个 GitHub issue 来跟踪此任务?

src/packages/inputnumber/inputnumber.tsx Outdated Show resolved Hide resolved
Comment on lines +223 to +234
onBlur?.(e)
const valueStr = parseValue(e.target.value)
if (valueStr === null) {
if (allowEmpty) {
setShadowValue(null)
} else {
setShadowValue(defaultValue)
}
} else {
setShadowValue(clampValue(valueStr) as any)
}
async && handleValueChange(valueStr, e)
Copy link

Choose a reason for hiding this comment

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

代码无误,但请添加测试!

handleBlur 函数基于夹紧输入设置影子值,并在异步模式下有条件地调用 handleValueChange

根据静态分析工具的提示,以下代码行未覆盖测试:#L226-L230。请添加相应的测试。

您希望我生成单元测试代码还是创建一个 GitHub issue 来跟踪此任务?

Tools
GitHub Check: codecov/patch

[warning] 226-230: src/packages/inputnumber/inputnumber.tsx#L226-L230
Added lines #L226 - L230 were not covered by tests

src/packages/inputnumber/inputnumber.taro.tsx Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant