Skip to content

Conversation

@Passing-of-A-Dream
Copy link
Contributor

@Passing-of-A-Dream Passing-of-A-Dream commented Nov 7, 2025

fix: #6992 修复 Space 组件在 横向布局时最后一个元素有 margin 导致的布局错误

Summary by CodeRabbit

发布说明

  • Bug Fixes
    • 修复了水平布局中最后一项元素的多余间距问题,确保最后一项不显示不必要的右边距,使间距显示更加整洁一致。

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Nov 7, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

Preview is ready

@coderabbitai
Copy link

coderabbitai bot commented Nov 7, 2025

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

Walkthrough

对 Space 组件的样式做了微调:在水平布局中为最后一个 .adm-space-item 增加了 margin-right: 0,以移除最后一项的多余右侧间距。

Changes

统一分类 / 文件 变更摘要
Space 组件样式调整
src/components/space/space.less
在水平布局中为最后一个 .adm-space-item 添加 margin-right: 0,移除最后一项的多余右侧外边距。

Sequence Diagram(s)

(本次更改仅为样式修正,无控制流变更,故不提供序列图。)

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 分钟

  • 单一样式文件(CSS/LESS)中的小范围修改
  • 复验点:不同对齐方式(尤其 justify="center")和断点下的视觉效果

Poem

🐰
我是小兔修边角,
把尾巴空隙悄悄趟。
最后一位不再挤,
布局整齐心欢畅。 🥕

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题清晰准确地反映了主要变更:修复Space组件在justify="center"布局下最后一个元素的布局错误。
Linked Issues check ✅ Passed 代码变更符合链接问题#6992的要求:通过添加last-child选择器移除最后一个元素的margin-right,解决了布局错误。
Out of Scope Changes check ✅ Passed 代码变更完全在范围内,仅修改space.less文件以修复特定的布局问题,没有无关的改动。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 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 3e79a6a and c8c7812.

📒 Files selected for processing (1)
  • src/components/space/space.less (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/space/space.less
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: build preview
  • GitHub Check: check
  • GitHub Check: compressed-size
  • GitHub Check: size
  • GitHub Check: build

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 @Passing-of-A-Dream, 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!

此拉取请求旨在优化 Space 组件的布局表现,通过精确控制最后一个元素的边距,消除了因不必要的 marginpadding 导致的视觉偏差,从而提升了组件在不同对齐方式下的显示准确性。

Highlights

  • 修复布局问题: 解决了 Space 组件在某些布局下(例如 justify="center")最后一个元素会多出一个 margin 的问题,确保布局的视觉一致性。
  • 样式调整: 为 Space 组件的子元素 .@{class-prefix-space}-item 增加了 :last-child 伪类选择器,以移除最后一个元素的 margin-right 和在 flex-wrap 模式下的 padding-bottom
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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 7, 2025

npm i https://pkg.pr.new/ant-design/ant-design-mobile/antd-mobile@6995

commit: c8c7812

@Passing-of-A-Dream Passing-of-A-Dream changed the title fixSpace justify="center"布局最后一个元素多了一个margin fix: Space组件在 justify="center" 布局下最后一个元素有布局错误 Nov 7, 2025
@dosubot dosubot bot added the bug label Nov 7, 2025
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 旨在修复 Space 组件在使用 justify="center" 时最后一个元素多余外边距的问题。针对水平方向的修复是正确的,但为 wrap 模式添加的样式 (padding-bottom: 0) 会在换行且最后一行有多个元素时引入新的布局 bug。我已在代码中指出了这个问题并建议移除。此外,我还提出了一个使用 gap 属性进行重构的建议,这是一种更现代、更简洁的实现方式,可以从根本上避免这类问题。

Comment on lines 37 to 39
&:last-child {
padding-bottom: 0;
}

Choose a reason for hiding this comment

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

critical

这部分修改会为换行布局引入新的 bug。:last-child 选择器只会匹配最后一个子元素。如果启用了 wrap 并且最后一行有多个元素,那么只有最后一个元素(即整组元素的最后一个)的 padding-bottom 会被移除,导致最后一行内的元素垂直方向无法对齐。

实际上,父容器上的 margin-bottom: calc(var(--gap-vertical) * -1) 已经正确地处理了最后一行多余的 padding-bottom,它通过负外边距将整个容器的底部“拉上来”,从而抵消了最后一行的内边距。因此,这里的修改是不必要的,并且是有害的,应当移除。

Comment on lines 26 to 41
> .@{class-prefix-space}-item {
margin-right: var(--gap-horizontal);
&:last-child {
margin-right: 0;
}
}
&.@{class-prefix-space}-wrap {
flex-wrap: wrap;
margin-bottom: calc(var(--gap-vertical) * -1);
> .@{class-prefix-space}-item {
padding-bottom: var(--gap-vertical);
&:last-child {
padding-bottom: 0;
}
}
}

Choose a reason for hiding this comment

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

medium

虽然移除最后一个元素的 margin-right 确实解决了 justify-content: center 时的居中问题,但目前通过子元素 margin 和父元素负 margin 来实现间距的整体方案比较复杂,并且容易在边缘场景下出错(比如这次 wrap 模式下的问题)。

一个更现代、更健壮的方案是直接在 flex 容器上使用 gap 属性。这能极大地简化 CSS 代码,并且能更好地处理换行场景。

建议考虑将这部分重构为使用 gap 属性,例如:

.@{class-prefix-space}-horizontal {
  flex-direction: row;
  column-gap: var(--gap-horizontal); // 水平间距
  &.@{class-prefix-space}-wrap {
    flex-wrap: wrap;
    row-gap: var(--gap-vertical); // 换行后的垂直间距
  }
}

这样就可以移除所有在 .@{class-prefix-space}-item 上设置的 margin/padding 规则,以及父容器上的负 margin 规则。考虑到项目中已经使用了 CSS 变量,浏览器的 gap 属性支持度应该不是问题。

@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.94%. Comparing base (d5e8422) to head (c8c7812).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6995      +/-   ##
==========================================
- Coverage   92.96%   92.94%   -0.02%     
==========================================
  Files         337      337              
  Lines        7359     7359              
  Branches     1834     1834              
==========================================
- Hits         6841     6840       -1     
- Misses        510      511       +1     
  Partials        8        8              

☔ 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.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Space justify="center"布局最后一个元素多了一个margin

2 participants