8000 feat: support onActive by zombieJ · Pull Request #1154 · react-component/select · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: support onActive #1154

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

Merged
merged 4 commits into from
May 27, 2025
Merged

feat: support onActive #1154

merged 4 commits into from
May 27, 2025

Conversation

zombieJ
Copy link
Member
@zombieJ zombieJ commented May 26, 2025

ref #1153

Summary by CodeRabbit

  • 新功能
    • 为选择组件新增了 onActive 回调属性,可在选项激活变化时触发回调。
  • 测试
    • 增强了可访问性相关测试,验证 onActive 回调在不同用户操作下的调用情况。
  • 优化
    • 优化了选项列表自动滚动到激活项的时机,提升交互体验。

Copy link
vercel bot commented May 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
select ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 27, 2025 7:39am

Copy link
Contributor
coderabbitai bot commented May 26, 2025

"""

Walkthrough

本次更新在 Select 组件及其使用示例中引入了新的 onActive 回调属性,用于在激活选项变化时通知外部。示例和测试文件均已相应调整,以验证该回调的调用时机和参数。此外,优化了 OptionList 组件中激活选项滚动的时序逻辑。

Changes

文件/分组 变更摘要
docs/examples/combobox.tsx, docs/examples/controlled.tsx 新增 onActive 方法并传递给 Select 组件,打印激活值或日志。
src/Select.tsx SelectProps 接口新增可选 onActive 回调,组件内部异步调用以防止多次快速触发。
tests/Accessibility.test.tsx 新增/增强测试,验证 onActive 回调在不同交互下的调用情况。
src/OptionList.tsx 优化激活选项滚动逻辑,调整 setActive 和 scrollIntoView 的调用时序。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Combobox
    participant Controlled
    participant Select

    User->>Combobox: 交互(输入、键盘事件)
    Combobox->>Select: 传递 onActive 回调
    Select->>Select: 选项激活状态变化
    Select-->>Combobox: 调用 onActive(activeValue)
    Combobox-->>Console: 输出激活值

    User->>Controlled: 交互(输入、键盘事件)
    Controlled->>Select: 传递 onActive 回调
    Select->>Select: 选项激活状态变化
    Select-->>Controlled: 调用 onActive(activeValue)
    Controlled-->>Console: 输出激活日志
Loading

Suggested reviewers

  • afc163

Poem

小兔写代码,新增回调忙,
选项激活变,onActive 报方向。
测试细细查,输入键盘忙,
控件更聪明,体验更流畅!
🐇✨
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

tests/Accessibility.test.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /.eslintrc.js
Error: Cannot find module '@umijs/fabric/dist/eslint'
Require stack:

  • /.eslintrc.js
  • /node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1405:15)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1061:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1066:22)
    at Module._load (node:internal/modules/cjs/loader:1215:37)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
    at Module.require (node:internal/modules/cjs/loader:1491:12)
    at require (node:internal/modules/helpers:135:16)
    at Object. (/.eslintrc.js:1:14)
    at Module._compile (node:internal/modules/cjs/loader:1734:14)

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 89ddfaf and 80d0da4.

📒 Files selected for processing (1)
  • tests/Accessibility.test.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/Accessibility.test.tsx
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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 May 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.27%. Comparing base (faa487c) to head (80d0da4).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1154   +/-   ##
=======================================
  Coverage   98.27%   98.27%           
=======================================
  Files          39       39           
  Lines        1503     1508    +5     
  Branches      455      456    +1     
=======================================
+ Hits         1477     1482    +5     
  Misses         26       26           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor
@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: 0

🧹 Nitpick comments (1)
docs/examples/controlled.tsx (1)

50-52: 建议使用 console.log 而不是 console.error

在示例代码中,onActive 回调用于展示功能,应该使用 console.log 而不是 console.error,因为这不是错误情况。

   => {
-    console.error('onActive', value);
+    console.log('onActive', value);
  };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 529377d and 2060988.

📒 Files selected for processing (3)
  • docs/examples/controlled.tsx (2 hunks)
  • src/OptionList.tsx (1 hunks)
  • src/Select.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Select.tsx
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/OptionList.tsx (2)
src/Select.tsx (1)
  • RawValueType (70-70)
src/interface.ts (1)
  • RawValueType (3-3)
🔇 Additional comments (2)
docs/examples/controlled.tsx (1)

76-76: onActive 属性传递正确

正确地将 onActive 回调传递给 Select 组件,实现符合预期。

src/OptionList.tsx (1)

157-172: 优化活跃选项状态更新的时序逻辑

这个改动很好地优化了活跃选项的状态更新时序:

  1. 立即更新活跃状态setActive 现在同步执行,确保 onActive 回调能够及时触发
  2. 延迟滚动操作:只有 scrollIntoView 被延迟执行,这是合理的,因为滚动是视觉操作,需要等待 DOM 更新
  3. 正确的清理逻辑timeoutId 声明在条件块外部,确保清理函数能够正确执行

这个改动完美支持了新的 onActive 功能,使得活跃状态变化能够立即通知外部组件。

@@ -127,6 +127,7 @@ export interface SelectProps<ValueType = any, OptionType extends BaseOptionType
// >>> Select
onSelect?: SelectHandler<ArrayElementType<ValueType>, OptionType>;
onDeselect?: SelectHandler<ArrayElementType<ValueType>, OptionType>;
onActive?: (value: ValueType) => void;

Choose a reason for hiding this comment

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

info 是不是也可以一起丢出去?鼠标和键盘

@zombieJ zombieJ merged commit 3bdb3b5 into master May 27, 2025
12 checks passed
@zombieJ zombieJ deleted the onActive branch May 27, 2025 08:12
@Wxh16144 Wxh16144 mentioned this pull request May 27, 2025

if (index !== -1) {
setActive(index);
let timeoutId: NodeJS.Timeout;
Copy link
Contributor

Choose a reason for hiding this comment

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

不应该是用 ReturnType<typeof setTimeout> 好一点么

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.

3 participants
0