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

feat: support prefix #1060

Merged
merged 1 commit into from
Oct 10, 2024
Merged

feat: support prefix #1060

merged 1 commit into from
Oct 10, 2024

Conversation

guoyunhe
Copy link
Contributor

@guoyunhe guoyunhe commented Aug 21, 2024

有时需要再 Select 左侧放图标或文字,类似 Input 的 prefix。

image

Summary by CodeRabbit

  • 新功能

    • 在组件中添加了可选的 prefix 属性,允许用户自定义选择器和基础选择组件的前缀图标或文本,增强了视觉表现和用户界面的灵活性。
    • 引入了 maxCount 属性,定义可选择的最大项数,进一步增强了组件的自定义能力。
    • 更新了示例文档,展示如何在组件中使用新的 prefix 属性。
  • 样式改进

    • 修改了选择搜索组件的样式,优化了布局控制,提高了用户界面的响应性和一致性。
  • 文档

    • 更新了 README.md 文件,增加了关于新 prefixmaxCount 属性的说明,帮助用户更好地理解和使用这些功能。
  • 测试

    • 增强了对 Select.Multiple 组件的测试覆盖,新增了验证 prefix 属性功能的测试用例。

Copy link

vercel bot commented Aug 21, 2024

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 Oct 10, 2024 2:28am

README.md Outdated
@@ -121,6 +121,7 @@ export default () => (
| showAction | actions trigger the dropdown to show | String[]? | - |
| autoFocus | focus select after mount | boolean | - |
| autoClearSearchValue | auto clear search input value when multiple select is selected/deselected | boolean | true |
| prefix | specify the select prefix icon or text | ReactNode | - | |
Copy link
Member

Choose a reason for hiding this comment

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

prefixIcon 吧,和suffixIcon 对应上

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我在实践中发现 prefix 和 suffixIcon 并不是对应的,prefix 是 relative 布局,不会和搜索框重叠,而 suffixIcon 是 absolute 布局,可能会和搜索框重叠(虽然可以用 CSS 定宽 padding/margin 解决,但是不能动态计算,导致 suffixIcon 不能是任意宽度的内容)。
image

Copy link
Member

Choose a reason for hiding this comment

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

当年没有 flex 布局用的 absolute。前置后和后置是等价的。从 API 看一个叫 prefix 却没有对应的 suffix,一个叫 suffixIcon 却没有对应的 prefixIcon,相当诡异。

Copy link
Member

Choose a reason for hiding this comment

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

prefix 和 suffix 对应,可以把 suffixIcon 废弃掉,重命名为 suffix,并重构为 flex 布局。

@@ -72,6 +72,7 @@ export interface SelectorProps {
disabled?: boolean;
placeholder?: React.ReactNode;
removeIcon?: RenderNode;
prefix?: RenderNode;
Copy link
Member

Choose a reason for hiding this comment

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

为什么不和 suffixIcon 一样,放 BaseSelect 里渲染?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

尝试了一下,如果放在 BaseSelect 里 flex 布局,preffix 会跑到 border 外面,视觉效果是不符合预期的
image

Copy link
Contributor

coderabbitai bot commented Sep 4, 2024

Walkthrough

此次更改引入了一个新的可选属性 prefix,允许用户在选择组件中指定图标或文本作为前缀。此属性在多个组件中实现,包括 BaseSelectSelector,并在相关文档中进行了更新。此外,CSS 样式也进行了调整,以改善组件的布局和视觉表现。

Changes

文件 更改摘要
README.md 新增 prefixmaxCount 属性,允许用户指定选择组件的前缀图标或文本及最大选择项数。
assets/index.less 修改 .search-input-without-border.rc-select-selection-search 类的样式,新增 position: relative;,移除 .rc-select-multiple .rc-select-selectorflex-wrap.rc-select-selection-overflowwidth: 100%;
docs/examples/custom-icon.tsx CustomIconComponentTest 中添加 prefix 属性,值为 "Foobar",并更新图标渲染逻辑。
src/BaseSelect/index.tsx BaseSelectProps 接口中新增 prefix 属性,类型为 ReactNode
src/Selector/SingleSelector.tsx 移动占位符显示逻辑至值显示之前,确保占位符一致性。
src/Selector/index.tsx SelectorProps 接口中新增 prefix 属性,类型为 ReactNode
tests/Multiple.test.tsx Select 组件新增测试用例,验证静态前缀的渲染功能。

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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • 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 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 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 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 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 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
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

Outside diff range, codebase verification and nitpick comments (2)
docs/examples/custom-icon.tsx (2)

106-106: 考虑让前缀值可配置。

将前缀值硬编码为 "Foobar" 可能不适合所有用例。建议通过 props 让前缀值可配置,以提高组件的灵活性和可重用性。

例如,可以应用以下更改:

- prefix="Foobar"
+ prefix={this.props.prefix}

然后在使用 CustomIconComponent 时传递 prefix 属性:

<CustomIconComponent prefix="Foobar" />

197-197: 考虑让前缀值可配置。

将前缀值硬编码为 "Foobar" 可能不适合所有用例。建议通过 props 让前缀值可配置,以提高组件的灵活性和可重用性。

例如,可以应用以下更改:

- prefix="Foobar"
+ prefix={this.props.prefix}

然后在使用 Test 组件时传递 prefix 属性:

<Test prefix="Foobar" />
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b39c28a and cdfd8eb.

Files ignored due to path filters (2)
  • tests/__snapshots__/Combobox.test.tsx.snap is excluded by !**/*.snap
  • tests/__snapshots__/ssr.test.tsx.snap is excluded by !**/*.snap
Files selected for processing (6)
  • README.md (1 hunks)
  • assets/index.less (3 hunks)
  • docs/examples/custom-icon.tsx (2 hunks)
  • src/BaseSelect/index.tsx (3 hunks)
  • src/Selector/SingleSelector.tsx (2 hunks)
  • src/Selector/index.tsx (3 hunks)
Additional context used
Markdownlint
README.md

124-124: Expected: 4; Actual: 5; Too many cells, extra data will be missing
Table column count

(MD056, table-column-count)

Additional comments not posted (8)
src/Selector/SingleSelector.tsx (1)

107-108: 代码更改没有问题!

将占位符节点移动到值显示部分之前的新位置可以改善用户界面,尤其是在输入为空时,为用户输入提供即时上下文。这种调整确保占位符在组件的输出中始终如一地呈现。

assets/index.less (2)

75-75: 代码更改没有问题!

添加 position: relative; 可以更好地控制子元素的布局。


Line range hint 118-118: 请验证此更改对组件的影响。

移除 flex-wrap: wrap; 可能会导致以下影响:

  • 多选项或溢出项的显示方式发生变化,可能变为线性排列。
  • 组件在处理多个选择或溢出项时的响应性可能受到影响。

请运行以下脚本来验证更改的影响:

src/Selector/index.tsx (2)

75-75: LGTM!

添加 prefix 属性到 SelectorProps 接口是一个有效的改动,它与支持 Select 组件中前缀的 PR 目标一致。使用 RenderNode 类型为用户提供了传递自定义渲染节点作为前缀的灵活性。


274-274: 之前的评论仍然有效,可以跳过。

zombieJ 之前建议将前缀渲染在 BaseSelect 中,类似于 suffixIcon,但是 guoyunhe 的回应表明这会导致意外的视觉效果。因此,在 Selector 组件的 JSX 结构中有条件地渲染 prefix 内容是一个有效的实现,它与 PR 的目标一致。该代码处理了 prefix 属性的函数和直接节点类型。

README.md (1)

124-124: 之前的评论仍然有效,讨论了属性的命名和行为。我同意 prefix 属性的命名和类型是合适的,不需要生成类似的评论。

Tools
Markdownlint

124-124: Expected: 4; Actual: 5; Too many cells, extra data will be missing
Table column count

(MD056, table-column-count)

src/BaseSelect/index.tsx (2)

176-176: 代码更改已批准。

新增的 prefix 属性已正确地从 props 中解构出来。


800-800: 代码更改已批准。

prefix 属性已正确地传递给了 Selector 子组件。

Copy link

codecov bot commented Sep 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.23%. Comparing base (7925a25) to head (f4a53f3).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1060   +/-   ##
=======================================
  Coverage   98.23%   98.23%           
=======================================
  Files          39       39           
  Lines        1473     1474    +1     
  Branches      438      416   -22     
=======================================
+ Hits         1447     1448    +1     
  Misses         26       26           

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

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cdfd8eb and a34ab5b.

Files ignored due to path filters (2)
  • tests/__snapshots__/Combobox.test.tsx.snap is excluded by !**/*.snap
  • tests/__snapshots__/ssr.test.tsx.snap is excluded by !**/*.snap
Files selected for processing (7)
  • README.md (1 hunks)
  • assets/index.less (3 hunks)
  • docs/examples/custom-icon.tsx (2 hunks)
  • src/BaseSelect/index.tsx (3 hunks)
  • src/Selector/SingleSelector.tsx (2 hunks)
  • src/Selector/index.tsx (3 hunks)
  • tests/Multiple.test.tsx (2 hunks)
Files skipped from review due to trivial changes (1)
  • src/Selector/SingleSelector.tsx
Files skipped from review as they are similar to previous changes (4)
  • assets/index.less
  • docs/examples/custom-icon.tsx
  • src/BaseSelect/index.tsx
  • src/Selector/index.tsx
Additional context used
Markdownlint
README.md

124-124: Expected: 4; Actual: 5; Too many cells, extra data will be missing
Table column count

(MD056, table-column-count)

Additional comments not posted (4)
README.md (1)

124-124: 新增 prefix 属性

此更改允许用户在选择组件中指定图标或文本作为前缀,增强了组件的功能性和可定制性。

Tools
Markdownlint

124-124: Expected: 4; Actual: 5; Too many cells, extra data will be missing
Table column count

(MD056, table-column-count)

tests/Multiple.test.tsx (3)

22-22: 导入语句更新审查

更新了导入语句以包括 screen,这对于新的测试用例是必要的。


377-384: 静态前缀显示测试

测试用例检查静态字符串前缀是否正确渲染。使用 screen.findByText 来断言前缀的存在,结构清晰,逻辑正确。


386-393: 动态前缀显示测试

测试用例评估当作为 prefix 属性提供返回字符串的函数时的行为。使用 screen.findByText 来断言前缀的存在,正确处理动态前缀,使用适当的断言来验证功能。

README.md Outdated Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a34ab5b and 4ef4478.

Files ignored due to path filters (2)
  • tests/__snapshots__/Combobox.test.tsx.snap is excluded by !**/*.snap
  • tests/__snapshots__/ssr.test.tsx.snap is excluded by !**/*.snap
Files selected for processing (7)
  • README.md (1 hunks)
  • assets/index.less (3 hunks)
  • docs/examples/custom-icon.tsx (2 hunks)
  • src/BaseSelect/index.tsx (3 hunks)
  • src/Selector/SingleSelector.tsx (2 hunks)
  • src/Selector/index.tsx (3 hunks)
  • tests/Multiple.test.tsx (2 hunks)
Files skipped from review due to trivial changes (2)
  • docs/examples/custom-icon.tsx
  • src/Selector/SingleSelector.tsx
Files skipped from review as they are similar to previous changes (5)
  • README.md
  • assets/index.less
  • src/BaseSelect/index.tsx
  • src/Selector/index.tsx
  • tests/Multiple.test.tsx

@@ -173,6 +173,7 @@ export interface BaseSelectProps extends BaseSelectPrivateProps, React.AriaAttri

// >>> Icons
allowClear?: boolean | { clearIcon?: RenderNode };
prefix?: RenderNode;
Copy link
Member

Choose a reason for hiding this comment

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

不要 renderProps,用户 HOC 自行转成 func 就行了。rc-select 不用支持。

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

🧹 Outside diff range and nitpick comments (6)
src/Selector/SingleSelector.tsx (1)

107-108: 代码更改看起来不错,建议小幅改进以提高可读性。

这个更改正确地将 placeholderNode 的渲染移到了更合适的位置,符合支持 Select 组件前缀的 PR 目标。放置在 selection-search span 内是恰当的,因为这可能是前缀可见的地方。

为了提高代码的可读性和可维护性,我建议添加一个简短的注释来解释为什么 placeholderNode 被放在这个位置。这将有助于其他开发者理解这个更改的意图。

建议在第 107 行之前添加以下注释:

+  {/* 渲染占位符或前缀(如果有的话) */}
   {/* Display placeholder */}
   {placeholderNode}
docs/examples/custom-icon.tsx (3)

Line range hint 106-112: 新增的prefix属性符合PR目标,图标渲染得到改进

这些更改很好地实现了PR的目标,同时改进了图标的渲染方式。

建议:

  • 考虑使用更有意义的prefix值,而不是"Foobar",以便更好地展示此功能的实际用途。
  • 可以考虑将prefix也设置为一个动态值或组件,以增加灵活性。

Line range hint 197-201: Test组件的更改与CustomIconComponent保持一致

这些更改与CustomIconComponent中的修改保持一致,很好地实现了PR的目标。

建议:

  • 考虑将prefix值设置为可配置的prop,而不是硬编码的"Foobar"。这样可以增加组件的灵活性,允许用户自定义prefix。
  • 可以添加一个示例,展示如何使用不同类型的prefix(如图标或文本)。

Line range hint 1-224: 总体评价:更改符合PR目标,实现了Select组件的prefix支持

这些更改很好地实现了PR的目标,为Select组件添加了prefix支持。主要亮点包括:

  1. 在CustomIconComponent和Test组件中一致地实现了prefix属性。
  2. 改进了图标渲染,使用getSvg函数确保了一致性。

建议进一步改进:

  1. 将prefix值设置为可配置的prop,增加灵活性。
  2. 添加更多示例,展示不同类型的prefix(如图标、文本)的使用。
  3. 考虑添加对prefix样式的自定义支持。

这些改进将使新功能更加强大和灵活,为用户提供更多定制选项。

tests/Multiple.test.tsx (1)

377-384: 新的测试用例结构良好,但需要小改动

这个测试用例很好地验证了静态前缀的功能。然而,screen.findByText() 是一个异步方法,建议将测试改为异步并使用 await

建议如下修改:

-  it('show static prefix', () => {
+  it('show static prefix', async () => {
     render(<Select mode="multiple" value={['']} prefix="Foobar">
       <Option value={1}>1</Option>
       <Option value={2}>2</Option>
     </Select>);

-    expect(screen.findByText('Foobar')).toBeTruthy();
+    expect(await screen.findByText('Foobar')).toBeTruthy();
   });
src/BaseSelect/index.tsx (1)

800-800: prefix 属性正确传递给 Selector 组件

prefix 属性已正确传递给 Selector 组件,这确保了前缀将被正确渲染。实现方式与其他属性的传递保持一致。

建议在 Selector 组件的文档中添加关于 prefix 属性的说明,以便其他开发者了解如何使用这个新功能。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4ef4478 and 9fdd953.

⛔ Files ignored due to path filters (2)
  • tests/__snapshots__/Combobox.test.tsx.snap is excluded by !**/*.snap
  • tests/__snapshots__/ssr.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (7)
  • README.md (1 hunks)
  • assets/index.less (1 hunks)
  • docs/examples/custom-icon.tsx (2 hunks)
  • src/BaseSelect/index.tsx (3 hunks)
  • src/Selector/SingleSelector.tsx (1 hunks)
  • src/Selector/index.tsx (3 hunks)
  • tests/Multiple.test.tsx (2 hunks)
🧰 Additional context used
🔇 Additional comments (9)
assets/index.less (1)

75-75: 更改看起来合理,但请验证其影响。

.@{select-prefix}-selection-search 类添加 position: relative; 是一个合理的更改,可能与新的前缀功能有关。这有助于更精确地定位子元素。

然而,建议验证此更改对现有布局没有负面影响。请考虑在不同场景下测试选择器组件,以确保其行为符合预期。

src/Selector/index.tsx (3)

75-75: 新增的 prefix 属性符合预期

新增的 prefix 属性类型为 React.ReactNode,这是一个很好的选择,因为它允许用户传入各种类型的内容(如文本、图标或自定义组件)作为前缀。这个改动与 PR 的目标一致,增强了 Select 组件的灵活性。


114-114: prefix 属性的解构符合组件的一致性

prefix 属性的解构与组件中其他属性的处理方式保持一致,并且它在解构列表中的位置也很合适,与其他视觉相关的属性放在一起。这种做法有助于保持代码的可读性和一致性。


274-274: 前缀元素的渲染实现得当,但需要注意样式影响

前缀元素的条件渲染和类名设置都很合理。将前缀 div 放置在 selectNode 之前也符合左侧前缀的设计要求。这种实现方式为样式和布局控制提供了灵活性。

然而,建议考虑以下几点:

  1. 确保新增的前缀元素不会对现有的选择器布局产生负面影响。
  2. 可能需要更新相关的 CSS 样式,以确保前缀与选择器的其他部分能够正确对齐和间距。
  3. 考虑在组件的文档中添加关于如何正确使用和样式化前缀的指导。

为了验证样式的一致性,请运行以下脚本来检查相关的 CSS 文件是否已更新:

README.md (1)

124-124: 新属性 'prefix' 添加正确

'prefix' 属性的添加符合拉取请求的目标,支持在 Select 组件中使用前缀。描述简洁明了,表格格式也正确。

不过,根据之前的评论,似乎曾就命名约定进行过讨论('prefix' 与 'prefixIcon')。建议确认 'prefix' 是否为最终商定的名称。如果是,那么这个更改是恰当的。

tests/Multiple.test.tsx (2)

22-22: 导入 screen 是个好的做法

从 '@testing-library/react' 导入 screen 是正确的,因为它在新的测试用例中被使用。这符合按需导入的最佳实践。


Line range hint 385-685: 现有测试保持不变,这是个好迹象

在查看提供的代码时,没有发现对现有测试的重大修改。这表明新添加的前缀功能与现有行为兼容,不需要调整其他测试。这是保持向后兼容性的好迹象。

src/BaseSelect/index.tsx (2)

176-176: 新属性 prefix 添加正确

prefix 属性的添加符合 PR 的目标,允许在 Select 组件左侧添加图标或文本。使用 React.ReactNode 类型提供了良好的灵活性。


Line range hint 1-863: 总体评价:prefix 功能实现完善

此 PR 成功地在 BaseSelect 组件中添加了 prefix 功能,实现方式简洁有效:

  1. 在 BaseSelectProps 接口中添加了 prefix 属性。
  2. prefix 属性正确传递给 Selector 组件。

这些更改与 PR 的目标一致,并保持了向后兼容性。代码风格和结构与文件的其余部分保持一致。

建议:

  1. 在 Selector 组件的文档中添加关于 prefix 属性的使用说明。
  2. 考虑添加一个简单的单元测试,以确保 prefix 属性被正确传递和渲染。

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

🧹 Outside diff range and nitpick comments (2)
README.md (1)

124-124: 新属性 prefix 的添加是个很好的改进,但有一些建议

这个新属性的添加确实增强了 Select 组件的功能,允许用户在选择框左侧添加图标或文本。然而,有几点需要考虑:

  1. 默认值 "-" 可能会引起混淆。建议将其改为 "undefined" 或 "-" 并添加说明,表示默认不显示前缀。

  2. 之前的讨论中提到了命名一致性的问题。考虑是否应该使用 "prefixIcon" 来与 "suffixIcon" 保持一致,或者将 "suffixIcon" 改为 "suffix"。这样可以提高 API 的一致性和可理解性。

您是否考虑过这些建议?如果需要,我可以协助您修改文档或实现代码。

tests/Multiple.test.tsx (1)

377-384: 新的测试用例有效验证了静态前缀功能

这个测试用例很好地验证了 Select 组件中静态前缀的渲染。不过,为了增加测试的稳健性,我建议使用更具体的断言方法。

考虑使用以下方式改进测试:

- expect(screen.findByText('Foobar')).toBeTruthy();
+ expect(screen.getByText('Foobar')).toBeInTheDocument();

这样的修改可以提供更明确的错误信息,并确保元素确实在文档中。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9fdd953 and f4a53f3.

⛔ Files ignored due to path filters (2)
  • tests/__snapshots__/Combobox.test.tsx.snap is excluded by !**/*.snap
  • tests/__snapshots__/ssr.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (7)
  • README.md (1 hunks)
  • assets/index.less (1 hunks)
  • docs/examples/custom-icon.tsx (2 hunks)
  • src/BaseSelect/index.tsx (3 hunks)
  • src/Selector/SingleSelector.tsx (1 hunks)
  • src/Selector/index.tsx (3 hunks)
  • tests/Multiple.test.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • assets/index.less
  • docs/examples/custom-icon.tsx
  • src/BaseSelect/index.tsx
  • src/Selector/SingleSelector.tsx
  • src/Selector/index.tsx
🧰 Additional context used
🔇 Additional comments (1)
tests/Multiple.test.tsx (1)

22-22: 导入 screen 是一个好的做法

从 '@testing-library/react' 导入 screen 是使用 React Testing Library 时的常见做法。这将使得在测试中查询渲染的组件元素变得更加容易和直观。

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