Skip to content

Conversation

HaixingOoO
Copy link
Collaborator

🤔 这个 PR 的性质是?

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

🔗 相关 Issue

💡 需求背景和解决方案

重构Affix组件的实现

📝 更新日志

  • refactor(Affix): 重构 Affix 组件

  • 本条 PR 不需要纳入 Changelog

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the Affix component with a cleaner implementation that improves maintainability and fixes positioning logic. The refactoring replaces a complex imperative approach with a more declarative React-based state management.

  • Introduces new utility functions for calculating fixed positioning
  • Refactors the component to use React hooks and state management patterns
  • Updates test cases to properly verify the new implementation

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/components/affix/Affix.tsx Complete refactor of Affix component with new state management and positioning logic
packages/components/affix/utils.ts New utility functions for calculating fixed top and bottom positions
packages/components/affix/_example/container.tsx Updates example to use proper event handling pattern
packages/components/_util/dom.ts Adds utility function for getting target element DOMRect
packages/components/affix/tests/affix.test.tsx Updates tests to work with refactored implementation
test/snap/snapshots/ssr.test.jsx.snap Updated snapshots to include empty class attributes
test/snap/snapshots/csr.test.jsx.snap Updated snapshots to include empty class attributes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +87 to +111
let top = 0;
if (fixedTop !== undefined) {
newState.affixStyle = {
position: 'fixed',
top: fixedTop,
width: placeholderRect.width,
height: placeholderRect.height,
zIndex,
};
newState.placeholderStyle = {
width: placeholderRect.width,
height: placeholderRect.height,
};
top = fixedTop;
} else if (fixedBottom !== undefined) {
newState.affixStyle = {
position: 'fixed',
bottom: fixedBottom,
width: placeholderRect.width,
height: placeholderRect.height,
zIndex,
};
newState.placeholderStyle = {
width: placeholderRect.width,
height: placeholderRect.height,
Copy link
Preview

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

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

The width and height properties are duplicated in both the fixedTop and fixedBottom branches. Consider extracting these common properties into a shared object to reduce duplication.

Suggested change
let top = 0;
if (fixedTop !== undefined) {
newState.affixStyle = {
position: 'fixed',
top: fixedTop,
width: placeholderRect.width,
height: placeholderRect.height,
zIndex,
};
newState.placeholderStyle = {
width: placeholderRect.width,
height: placeholderRect.height,
};
top = fixedTop;
} else if (fixedBottom !== undefined) {
newState.affixStyle = {
position: 'fixed',
bottom: fixedBottom,
width: placeholderRect.width,
height: placeholderRect.height,
zIndex,
};
newState.placeholderStyle = {
width: placeholderRect.width,
height: placeholderRect.height,
const sharedRectStyle = {
width: placeholderRect.width,
height: placeholderRect.height,
};
let top = 0;
if (fixedTop !== undefined) {
newState.affixStyle = {
position: 'fixed',
top: fixedTop,
...sharedRectStyle,
zIndex,
};
newState.placeholderStyle = {
...sharedRectStyle,
};
top = fixedTop;
} else if (fixedBottom !== undefined) {
newState.affixStyle = {
position: 'fixed',
bottom: fixedBottom,
...sharedRectStyle,
zIndex,
};
newState.placeholderStyle = {
...sharedRectStyle,

Copilot uses AI. Check for mistakes.

Copy link
Contributor

github-actions bot commented Sep 6, 2025

完成

Copy link

pkg-pr-new bot commented Sep 6, 2025

tdesign-react-demo

npm i https://pkg.pr.new/tdesign-react@3797

commit: c75c6f7

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.

1 participant