nutui-react icon indicating copy to clipboard operation
nutui-react copied to clipboard

修改picker组件issue

Open dragonfly-captain opened this issue 1 year ago • 2 comments

🤔 这个变动的性质是?

  • [ ] 新特性提交
  • [√ ] 日常 bug 修复
  • [ ] 站点、文档改进
  • [ ] 演示代码改进
  • [ ] 组件样式/交互改进
  • [ ] TypeScript 定义更新
  • [ ] 包体积优化
  • [ ] 性能优化
  • [ ] 功能增强
  • [ ] 国际化改进
  • [ ] 重构
  • [ ] 代码风格优化
  • [ ] 测试用例
  • [ ] 分支合并
  • [ ] 其他改动(是关于什么的改动?)

🔗 相关 Issue

  1. form下的picker在第一次不选择选项,直接取消选择后再次点击picker,出现第一项被选中的问题https://github.com/jdf2e/nutui-react/issues/2290
  2. Picker 和 FormItem 搭配使用时,ref.open() 会触发 Picker 的 onClose https://github.com/jdf2e/nutui-react/issues/2312

💡 需求背景和解决方案

背景:线上issue 解决方案:通过修改源代码的方式对issue进行修改,不破坏原逻辑,对性能没有影响

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项。⚠️

  • [√ ] 文档已补充或无须补充
  • [ √ ] 代码演示已提供或无须提供
  • [ √ ] TypeScript 定义已补充或无须补充
  • [ √ ] fork仓库代码是否为最新避免文件冲突
  • [√ ] Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 错误修复
    • 更新了选择器组件的onChange事件处理逻辑,以确保在确认选择时行为正确。

dragonfly-captain avatar Jun 18 '24 02:06 dragonfly-captain

Walkthrough

这些更改涉及InternalPicker组件内逻辑和控制流的修改。具体来说,调整了基于所选值的onChange事件处理,以解决特定问题并在确认选择时确保正确行为。此外,还重构了useEffect钩内的setInnerValue逻辑以处理选择的值并防止不必要的修改。

Changes

文件 更改摘要
src/packages/picker/picker.tsx 更新onChange方法以条件性地调用props.onConfirm、重构useEffect内的setInnerValue逻辑、移除内联useEffect的onChange方法。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Picker as InternalPicker
    participant ConfirmHandler

    User ->> Picker: Selects Value
    Picker ->> Picker: setInnerValue(newValue)
    alt if val is present
        Picker ->> ConfirmHandler: props.onConfirm(val)
    end
    Picker ->> User: onChange Callback

Poem

内部挑选更新忙,
onChange逻辑细思量。
确认选择无误差,
修改流畅前景亮。
代码如诗般绽放,
程序健壮无限畅。


Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL

Commits

Files that changed from the base of the PR and between cfc5be39eb0e44e0e70549652990173e81ae8276 and 76a5e85c9178b266e74834b1563eb9b0f5fe6068.

Files selected for processing (1)
  • src/packages/picker/picker.tsx (5 hunks)
Additional context used
Biome
src/packages/picker/picker.tsx

[error] 143-144: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 262-264: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 280-282: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 305-317: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event. (lint/a11y/useKeyWithClickEvents)

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.


[error] 322-327: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event. (lint/a11y/useKeyWithClickEvents)

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.

Additional comments not posted (1)
src/packages/picker/picker.tsx (1)

Line range hint 143-144: 应使用可选链 (Optional Chaining) 操作符来简化代码。 [REFACTOR_SUGGESTIOn]

- columnOptions && columnOptions.children
+ columnOptions?.children

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:

:bangbang: 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 Configration 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.

coderabbitai[bot] avatar Jun 18 '24 02:06 coderabbitai[bot]

请问这个问题啥时候解决呢 今天就遇到了

Lin-Min avatar Sep 19 '24 06:09 Lin-Min