Skip to content

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Nov 7, 2025

resize 样式不生效,两者会冲突。因为 style 的优先级会更高一些导致覆盖。

Summary by CodeRabbit

发版说明

  • 重构

    • 统一并优化了文本区域的样式合并与应用逻辑,确保 resize 样式按需生效。
  • 测试

    • 新增针对调整大小样式的测试用例,验证通过多种方式设置生效。
  • 杂项

    • 清理测试文件中的未使用导入,减小测试维护成本。

@coderabbitai
Copy link

coderabbitai bot commented Nov 7, 2025

Caution

Review failed

The pull request is closed.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

新增一个名为 mergedStyles 的 memo,用于有条件地将 resize 合并进传给 TextAreastyles 对象;同时清理了测试中的未使用导入并新增针对 resize 样式的测试覆盖。

Changes

类别 / 文件 变更摘要
核心样式重构
src/Mentions.tsx
新增 mergedStyles memo,若 style.resizestyles.textarea.resize 存在则将其合并到单一 styles 对象并传给 TextArea,替代之前分别传递的 style/styles 方式。
测试导入清理
tests/DropdownMenu.spec.tsx
移除未使用导入:fireEventKeyCodeexpectMeasuring;保留 renderactMentionsUnstableContextsimulateInput
样式测试覆盖
tests/Mentions.spec.tsx
添加 "resize style" 测试套件:验证通过组件 style 属性和 styles.textarea 两种方式分别应用 resize 样式的行为。

Sequence Diagram(s)

sequenceDiagram
    participant Consumer as 使用方组件
    participant Mentions as Mentions
    participant Memo as mergedStyles (memo)
    participant TextArea as TextArea

    note right of Mentions#lightgreen: 渲染流程(变更后)
    Consumer->>Mentions: 传入 props (style, styles, ...)
    Mentions->>Memo: 计算 mergedStyles(合并 resize 到 styles.textarea)
    Memo-->>Mentions: 返回 mergedStyles
    Mentions->>TextArea: 通过 `styles={mergedStyles}` 传递样式
    TextArea-->>Consumer: 渲染带合并样式的 textarea
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 分钟

  • 关注点:
    • mergedStyles 的合并优先级与边界情况(undefined / null / 字符串值)
    • 确认没有意外覆盖其他 styles 子项
    • 新增测试是否覆盖所有预期路径(stylestyles.textarea

Possibly related PRs

Suggested reviewers

  • afc163

Poem

🐰 样式汇成一线来,
textarea 轻摆不彷徨,
测试新添来把关,
小小合并见匠心,
胡萝卜庆功笑开场 🍃

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确总结了主要变更,解决了resize样式优先级冲突的问题,与代码更改直接相关。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 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 dba997f and 713239e.

📒 Files selected for processing (1)
  • src/Mentions.tsx (2 hunks)

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @zombieJ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where the resize style property was not functioning as expected on the Mentions component's textarea. The core problem stemmed from how style properties, specifically resize, were being passed and prioritized, leading to an override. The solution involves a refined approach to merging and applying these styles, ensuring that the resize property is correctly recognized and rendered. This change enhances the component's styling flexibility and includes new tests to validate the fix.

Highlights

  • Fix resize style application: The resize style property was not correctly applied to the Mentions component's TextArea due to a style priority conflict, which has now been resolved.
  • Unified style merging: Introduced a mergedStyles object using React.useMemo to consolidate the resize property from either the style or styles.textarea props, ensuring it's correctly passed to the underlying TextArea component.
  • Added test coverage: New test cases were added to Mentions.spec.tsx to verify that the resize style is correctly applied whether provided via the style prop or the styles.textarea prop.
  • Test cleanup: Removed unused imports (fireEvent, KeyCode, expectMeasuring) from DropdownMenu.spec.tsx, streamlining the test file.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.51%. Comparing base (ea9cf7d) to head (713239e).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #305      +/-   ##
==========================================
+ Coverage   98.48%   98.51%   +0.03%     
==========================================
  Files           8        8              
  Lines         264      270       +6     
  Branches       64       66       +2     
==========================================
+ Hits          260      266       +6     
  Misses          4        4              

☔ 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

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

这个 PR 修复了 resize 样式因为 style 属性覆盖而失效的问题,做得很好。通过 useMemo 合并 stylestyles 属性中的 resize 样式,确保了正确的优先级和应用。代码逻辑清晰,并且添加了相应的单元测试来覆盖这个修复,保证了代码质量。我有一个关于 useMemo 用法的重构建议,可以让代码更简洁,依赖关系更清晰。

src/Mentions.tsx Outdated
Comment on lines 480 to 493
const resizeStyle = styles?.textarea?.resize ?? style?.resize;
const mergedStyles = React.useMemo(() => {
const mergedTextareaStyle = { ...styles?.textarea };

// Only add resize if it has a valid value, avoid setting undefined
if (resizeStyle !== undefined) {
mergedTextareaStyle.resize = resizeStyle;
}

return {
...styles,
textarea: mergedTextareaStyle,
};
}, [resizeStyle, styles]);

Choose a reason for hiding this comment

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

medium

可以将 resizeStyle 的计算逻辑移到 useMemo 内部,这样可以使 useMemo 的依赖项更直接地反映其依赖的 props (stylestyles),而不是派生状态 resizeStyle。这能让代码更清晰,也更容易维护。

Suggested change
const resizeStyle = styles?.textarea?.resize ?? style?.resize;
const mergedStyles = React.useMemo(() => {
const mergedTextareaStyle = { ...styles?.textarea };
// Only add resize if it has a valid value, avoid setting undefined
if (resizeStyle !== undefined) {
mergedTextareaStyle.resize = resizeStyle;
}
return {
...styles,
textarea: mergedTextareaStyle,
};
}, [resizeStyle, styles]);
const mergedStyles = React.useMemo(() => {
const resizeStyle = styles?.textarea?.resize ?? style?.resize;
const mergedTextareaStyle = { ...styles?.textarea };
// Only add resize if it has a valid value, avoid setting undefined
if (resizeStyle !== undefined) {
mergedTextareaStyle.resize = resizeStyle;
}
return {
...styles,
textarea: mergedTextareaStyle,
};
}, [style, styles]);

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

🧹 Nitpick comments (1)
tests/Mentions.spec.tsx (1)

372-388: LGTM!测试覆盖良好

新增的测试用例正确验证了 resize 样式可以通过 style 属性和 styles.textarea 属性两种方式应用。

可选建议:考虑添加一个测试用例来验证优先级行为(当同时提供 style.resizestyles.textarea.resize 时,styles.textarea.resize 应该具有更高优先级):

it('should prioritize resize style from styles.textarea over style prop', () => {
  const { container } = renderMentions({
    style: { resize: 'horizontal' },
    styles: { textarea: { resize: 'vertical' } },
  });
  const textarea = container.querySelector('textarea');
  expect(textarea).toHaveStyle({ resize: 'vertical' });
});
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea9cf7d and dba997f.

📒 Files selected for processing (3)
  • src/Mentions.tsx (2 hunks)
  • tests/DropdownMenu.spec.tsx (1 hunks)
  • tests/Mentions.spec.tsx (1 hunks)
🔇 Additional comments (2)
src/Mentions.tsx (1)

507-507: LGTM!

将合并后的 styles 传递给 TextArea 组件的做法是正确的,确保了 resize 样式能够正确应用。

tests/DropdownMenu.spec.tsx (1)

2-4: LGTM!

移除未使用的导入是良好的代码维护实践,清理后的导入声明更加简洁明了。

@zombieJ zombieJ merged commit 17c9914 into master Nov 7, 2025
7 checks passed
@zombieJ zombieJ deleted the fix-resize branch November 7, 2025 08:49
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.

2 participants