Repository: arco-design/arco-design (ts)

Issue:
Anchor组件scrollContainer元素未传递到affix上
- [ ] I'm sure this does not appear in [the issue list of the repository](https://github.com/arco-design/arco-design/issues)

## Basic Info 
- **Package Name And Version:** @arco-design/web-react: 2.23.0
- **System:** MacOS
- **Browser:** Chrome
- **Reproduction Link:** https://codepen.io/liushuo-99/pen/oNeRpPY?editors=001

## What is expected?
可以通过监听scrollContainer查询到的容器来设置fixed，滚动距离 ≥ scrollTop时设置fixed样式

## Steps to reproduce
当滚动元素不是window时Anchor的fixed属性没有正常被设置，且滚动距离严格大于scrollTop值时才会被设置为fixed


<!-- generated by arco-issue. DO NOT REMOVE -->

Pull request:
fix: Anchor's scrollContainer should be added to Affix
<!--
  Thanks so much for your PR and contribution.

  Before submitting, please make sure to follow the Pull Request Guidelines: https://github.com/arco-design/arco-design/blob/main/CONTRIBUTING.md
-->

<!-- Put an `x` in "[ ]" to check a box) -->

## Types of changes

<!-- What types of changes does this PR introduce -->
- [ ] New feature
- [x] Bug fix
- [ ] Documentation change
- [ ] Coding style change
- [ ] Component style change
- [ ] Refactoring
- [ ] Performance improvement
- [ ] Test cases
- [ ] Continuous integration
- [ ] Typescript definition change
- [ ] Breaking change
- [ ] Others 

## Background and context

<!-- Explain what problem does the PR solve -->
<!-- Link to related open issues if applicable -->

## Solution

<!-- Describe how the problem is fixed in detail -->

## How is the change tested?

<!-- Unit tests should be added/updated for bug fixes and new features, if applicable -->
<!-- Please describe how you tested the change. E.g. Creating/updating unit tests or attaching a screenshot of how it works with your change -->

## Changelog

| Component | Changelog(CN) | Changelog(EN) | Related issues |
| --------- | ------------- | ------------- | -------------- |
| Anchor | fix: 修复 `Anchor` 组件设置 `affix`时，滚动容器未传递到 `Affix` 组件上的bug | fix: Fix the bug that the scroll container is not passed to the `Affix` component when the `Anchor` component is set to `affix` |   Close #209   |

## Checklist:

- [x] Test suite passes (`npm run test`)
- [x] Provide changelog for relevant changes (e.g. bug fixes and new features) if applicable.
- [x] Changes are submitted to the appropriate branch (e.g. features should be submitted to `feature` branch and others should be submitted to `main` branch)

## Other information

<!-- Please describe what other information that should be taken care of. E.g. describe the impact if introduce a breaking change -->


Patch:
diff --git a/components/Anchor/anchor.tsx b/components/Anchor/anchor.tsx
index 90e1a2e9..83462df6 100644
--- a/components/Anchor/anchor.tsx
+++ b/components/Anchor/anchor.tsx
@@ -67,11 +67,16 @@ function Anchor(baseProps: AnchorPropsWithChildren, ref) {
   const isFirstRender = useIsFirstRender();
 
   const scrollContainer = useRef<HTMLElement | Window>(null);
+
   useEffect(() => {
     const container = getContainer(propScrollContainer);
     scrollContainer.current = container;
   }, [propScrollContainer]);
 
+  const getAffixTarget = useCallback(() => {
+    return getContainer(propScrollContainer);
+  }, [propScrollContainer]);
+
   useImperativeHandle(
     ref,
     () => ({
@@ -245,7 +250,12 @@ function Anchor(baseProps: AnchorPropsWithChildren, ref) {
   );
 
   return affix ? (
-    <Affix offsetTop={offsetTop} offsetBottom={offsetBottom} style={affixStyle}>
+    <Affix
+      offsetTop={offsetTop}
+      offsetBottom={offsetBottom}
+      style={affixStyle}
+      target={getAffixTarget}
+    >
       {content}
     </Affix>
   ) : (
diff --git a/components/Tree/animation.tsx b/components/Tree/animation.tsx
index 128ca351..93e08483 100644
--- a/components/Tree/animation.tsx
+++ b/components/Tree/animation.tsx
@@ -84,14 +84,6 @@ const TreeAnimation = (props: PropsWithChildren<NodeProps>) => {
   let realHeight = treeContext.virtualListProps?.height;
   realHeight = isNumber(realHeight) ? realHeight : 0;
 
-  useEffect(() => {
-    // node set loadingMore but has no child nodes.
-    // Animation will not be triggered and needs to be removed manually
-    if (currentExpandKeys.indexOf(props._key) > -1 && filtedData.length === 0) {
-      treeContext.onExpandEnd(props._key);
-    }
-  }, [filtedData, currentExpandKeys]);
-
   return (
     <CSSTransition
       in={currentExpandKeys.indexOf(props._key) > -1 && filtedData.length > 0}
@@ -107,6 +99,7 @@ const TreeAnimation = (props: PropsWithChildren<NodeProps>) => {
       }}
       onEntering={(e) => {
         const scrollHeight = e.scrollHeight;
+
         e.style.height = expanded ? `${Math.min(realHeight || scrollHeight, scrollHeight)}px` : 0;
       }}
       onEntered={(e) => {


Test patch:
diff --git a/components/Anchor/__test__/index.test.tsx b/components/Anchor/__test__/index.test.tsx
index 74ec1fe7..ed9a837f 100644
--- a/components/Anchor/__test__/index.test.tsx
+++ b/components/Anchor/__test__/index.test.tsx
@@ -273,7 +273,8 @@ describe('Anchor', () => {
 
     // 去除原来监听1次。
     // 监听新的scrollContainer1次。
-    expect(containerMock).toHaveBeenCalledTimes(2);
+    // 透传到affix=>useCallback 再调用getContainer
+    expect(containerMock).toHaveBeenCalledTimes(4);
   });
 
   it('should call utils function correctly', () => {