Skip to content

Commit 6dd4fbf

Browse files
authored
fix: extra offset position not cover (#220)
* fix: extra should render in the filler * docs: update demo * test: update testcase
1 parent 9e14261 commit 6dd4fbf

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

examples/horizontal-scroll.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const Rect = ({ style }: { style?: React.CSSProperties }) => (
1414
background: 'blue',
1515
flex: 'none',
1616
borderInline: `1px solid red`,
17+
zIndex: 2,
1718
...style,
1819
}}
1920
>
@@ -104,17 +105,20 @@ const Demo = () => {
104105
boxSizing: 'border-box',
105106
}}
106107
extraRender={(info) => {
107-
const { offsetX, rtl: isRTL } = info;
108+
const { offsetX, offsetY, rtl: isRTL } = info;
108109
const sizeInfo = info.getSize('id_3', 'id_5');
109110

110111
return (
111112
<div
112113
style={{
113114
position: 'absolute',
114-
top: sizeInfo.top,
115+
// top: -offsetY,
116+
top: -offsetY + sizeInfo.top,
115117
height: sizeInfo.bottom - sizeInfo.top,
116-
[isRTL ? 'right' : 'left']: 100 - offsetX,
117-
background: 'rgba(255,0,0,0.1)',
118+
// [isRTL ? 'right' : 'left']: 100 - offsetX,
119+
[isRTL ? 'right' : 'left']: 100,
120+
background: 'rgba(255,0,0,0.9)',
121+
zIndex: 1,
118122
}}
119123
>
120124
Extra

src/Filler.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ const Filler = React.forwardRef(
8686
ref={ref}
8787
{...innerProps}
8888
>
89+
{extra}
8990
{children}
9091
</div>
9192
</ResizeObserver>
92-
93-
{extra}
9493
</div>
9594
);
9695
},

src/List.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
174174
);
175175

176176
// ========================== Visible Calculation =========================
177-
const { scrollHeight, start, end, offset } = React.useMemo(() => {
177+
const {
178+
scrollHeight,
179+
start,
180+
end,
181+
offset: fillerOffset,
182+
} = React.useMemo(() => {
178183
if (!useVirtual) {
179184
return {
180185
scrollHeight: undefined,
@@ -482,6 +487,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
482487
end,
483488
virtual: inVirtual,
484489
offsetX: offsetLeft,
490+
offsetY: fillerOffset,
485491
rtl: isRTL,
486492
getSize,
487493
});
@@ -541,7 +547,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
541547
prefixCls={prefixCls}
542548
height={scrollHeight}
543549
offsetX={offsetLeft}
544-
offsetY={offset}
550+
offsetY={fillerOffset}
545551
scrollWidth={scrollWidth}
546552
onInnerResize={collectHeight}
547553
ref={fillerInnerRef}

src/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface ExtraRenderInfo {
1919
virtual: boolean;
2020
/** Used for `scrollWidth` tell the horizontal offset */
2121
offsetX: number;
22+
offsetY: number;
2223

2324
rtl: boolean;
2425

tests/scrollWidth.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ describe('List.scrollWidth', () => {
187187
},
188188
});
189189

190+
expect(container.querySelector('.rc-virtual-list-holder-inner .bamboo')).toBeTruthy();
190191
expect(container.querySelector('.bamboo').textContent).toEqual(
191192
`${ITEM_HEIGHT}/${4 * ITEM_HEIGHT}`,
192193
);

0 commit comments

Comments
 (0)