Skip to content
Merged
6 changes: 5 additions & 1 deletion packages/x/components/bubble/BubbleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useXProviderContext } from '../x-provider';
import Bubble from './Bubble';
import { BubbleContext } from './context';
import DividerBubble from './Divider';
import { useCompatibleScroll } from './hooks/useCompatibleScroll';
import {
BubbleItemType,
BubbleListProps,
Expand Down Expand Up @@ -138,6 +139,8 @@ const BubbleList: React.ForwardRefRenderFunction<BubbleListRef, BubbleListProps>

const bubblesRef = React.useRef<BubblesRecord>({});

const { reset } = useCompatibleScroll(autoScroll ? scrollBoxRef.current : null);

// ============================ Prefix ============================
const { getPrefixCls } = useXProviderContext();

Expand Down Expand Up @@ -165,8 +168,9 @@ const BubbleList: React.ForwardRefRenderFunction<BubbleListRef, BubbleListProps>
const lastItemKey = items[items.length - 1]?.key || items.length;
React.useEffect(() => {
if (!scrollBoxRef.current) return;
reset();
scrollBoxRef.current?.scrollTo({ top: autoScroll ? 0 : scrollBoxRef.current.scrollHeight });
}, [lastItemKey, autoScroll]);
}, [lastItemKey, autoScroll, reset]);

// ============================= Refs =============================
useProxyImperativeHandle(ref, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,9 @@ exports[`renders components/bubble/demo/list.tsx extend context correctly 1`] =
<div
class="ant-bubble-list-scroll-box ant-bubble-list-autoscroll"
>
<div
style="bottom: 0px; flex-shrink: 0; pointer-events: none; height: 10px; visibility: hidden;"
/>
<div
class="ant-bubble css-var-_r_f_ ant-bubble-start ant-bubble-loading"
>
Expand Down Expand Up @@ -2763,6 +2766,9 @@ exports[`renders components/bubble/demo/list-scroll.tsx extend context correctly
<div
class="ant-bubble-list-scroll-box ant-bubble-list-autoscroll"
>
<div
style="bottom: 0px; flex-shrink: 0; pointer-events: none; height: 10px; visibility: hidden;"
/>
<div
class="ant-bubble css-var-_r_s_ ant-bubble-end"
>
Expand Down
Loading
Loading