-
-
Notifications
You must be signed in to change notification settings - Fork 691
feat(suggestion): onSelect 回调增加当前 item 信息 #718
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
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthrough此次修改主要在 Suggestion 组件中增强了类型安全性和灵活性。更新引入了泛型参数,用于定义 Changes
Sequence Diagram(s)sequenceDiagram
participant U as 用户
participant SC as Suggestion组件
participant IS as 内部逻辑
participant CB as onSelect回调
U->>SC: 触发键盘事件
SC->>IS: 调用 getValues(activePaths) 获取值
SC->>IS: 调用 getItems(activePaths) 获取选项
SC->>CB: 调用 onSelect(value, selectedOptions) 传递值和选项
Suggested reviewers
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
WalkthroughThis pull request introduces a new feature to the Changes
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
components/suggestion/index.zh-CN.md (3)
34-34
: 建议项类型定义更新:检查泛型参数设计
在第 34 行中,将items
的类型更新为SuggestionItem<T>[] | ((info: T) => SuggestionItem<K>[])
,通过引入两个泛型参数提升了类型安全性和灵活性。请确认此处 T 与 K 在组件应用场景中的用途和区别,并在文档中简要说明,以便开发者了解何时应使用函数形式返回建议项以及两者的语义差异。
37-37
: onSelect 回调更新:参数扩展说明建议
第 37 行中,onSelect
的类型由原来的(value: string) => void
更新为(value: string, item: SuggestionItem<T>) => void
,这增强了回调的可用信息。建议在文档中补充一个简单示例,说明如何利用新增加的item
参数来获得更多上下文信息,从而帮助开发者更好地理解和使用此特性。
50-57
: SuggestionItem 接口更新:增强子项目类型安全性
在第 50 至 57 行中,对SuggestionItem
接口进行了更新,将children
属性的类型改为SuggestionItem<T>[]
。此调整使得子项目可以继承泛型,提高类型一致性。建议在文档中增加一小段描述,展示如何利用此扩展来定制子项目的结构,从而让用户更直观地了解修改前后的区别和优势。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
components/suggestion/index.en-US.md
(2 hunks)components/suggestion/index.tsx
(4 hunks)components/suggestion/index.zh-CN.md
(2 hunks)components/suggestion/useActive.ts
(3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
components/suggestion/index.tsx (1)
components/x-provider/demo/use.tsx (1)
value
(24-143)
🔇 Additional comments (10)
components/suggestion/useActive.ts (3)
3-3
: 导入类型声明无误
导入SuggestionItem
类型的写法正确,符合当前文件的使用需求。
12-12
: 回调签名更新需要确认调用处
本次将onSelect
的参数从单一字符串数组扩展为(value: string[], options: SuggestionItem[])
,功能更强大。建议确认所有调用处、类型声明和文档能正确匹配此新签名。
106-106
: 在回调中传入完整选项信息
调用onSelect
时,新增了对被选择项的数组传递,可提供更丰富的上下文数据。实现看起来合理。components/suggestion/index.tsx (4)
11-20
: 泛型扩展设计合理
将SuggestionItem
定义为可扩展的泛型{ ... } & T
,在复用性与自定义场景下更具灵活性,设计良好。
36-36
: onSelect 回调参数扩展
onSelect?: (value: string, item: SuggestionItem) => void;
新增第二个参数可提供更多信息,增强了可用性。
110-110
: onInternalChange 方法签名变化
新增selectedOptions: SuggestionItem[]
,确保在最终回调中传递完整的选项数据。此变更与之前的泛型调整保持一致。
112-112
: 回调传参保持一致性
在此处使用valuePath[valuePath.length - 1]
和相应的selectedOptions
项生成更直观的单个值与选项。实现无问题。components/suggestion/index.en-US.md (3)
33-33
: items 属性类型扩展
将items
定义为SuggestionItem<T>[] | ((info: T) => SuggestionItem<K>[])
,强化在传入不同泛型时的灵活度,文档更新正确。
36-36
: onSelect 文档更新
onSelect
回调新增(value: string, item: SuggestionItem<T>)
,可同时获取所选值与对应对象,有利于更精细的处理。
49-55
: SuggestionItem 表格说明完善
将children
、extra
、icon
、label
、value
等属性在表格中进行了更详尽的列举,且结合了泛型声明,一目了然。
中文版模板 / Chinese template
🤔 This is a ...
🔗 Related Issues
💡 Background and Solution
给
onSelect
方法回调一个当前选中的 item,此外开发者可以在 item对象上扩展额外信息,增加泛型📝 Change Log
Summary by CodeRabbit