-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: Space组件在 justify="center" 布局下最后一个元素有布局错误 #6995
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: master
Are you sure you want to change the base?
fix: Space组件在 justify="center" 布局下最后一个元素有布局错误 #6995
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit 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. 📝 WalkthroughWalkthrough对 Space 组件的样式做了微调:在水平布局中为最后一个 Changes
Sequence Diagram(s)(本次更改仅为样式修正,无控制流变更,故不提供序列图。) Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 分钟
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
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. Comment |
Summary of ChangesHello @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! 此拉取请求旨在优化 Highlights
Using Gemini Code AssistThe 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
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 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
|
commit: |
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.
Code Review
这个 PR 旨在修复 Space 组件在使用 justify="center" 时最后一个元素多余外边距的问题。针对水平方向的修复是正确的,但为 wrap 模式添加的样式 (padding-bottom: 0) 会在换行且最后一行有多个元素时引入新的布局 bug。我已在代码中指出了这个问题并建议移除。此外,我还提出了一个使用 gap 属性进行重构的建议,这是一种更现代、更简洁的实现方式,可以从根本上避免这类问题。
src/components/space/space.less
Outdated
| &:last-child { | ||
| padding-bottom: 0; | ||
| } |
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.
| > .@{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; | ||
| } | ||
| } | ||
| } |
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.
虽然移除最后一个元素的 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|

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