Skip to content

Commit 3414e43

Browse files
committed
fix: Not collect height when list is invisible
1 parent 83067ae commit 3414e43

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

examples/basic.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable jsx-a11y/label-has-associated-control, jsx-a11y/label-has-for */
22
import * as React from 'react';
3-
import List from '../src/List';
3+
import List, { ListRef } from '../src/List';
44

55
interface Item {
66
id: string;
@@ -46,8 +46,9 @@ const TYPES = [
4646

4747
const Demo = () => {
4848
const [destroy, setDestroy] = React.useState(false);
49+
const [visible, setVisible] = React.useState(true);
4950
const [type, setType] = React.useState('dom');
50-
const listRef = React.useRef<List>(null);
51+
const listRef = React.useRef<ListRef>(null);
5152

5253
return (
5354
<React.StrictMode>
@@ -120,6 +121,15 @@ const Demo = () => {
120121
Scroll To key 50 (auto)
121122
</button>
122123

124+
<button
125+
type="button"
126+
onClick={() => {
127+
setVisible(v => !v);
128+
}}
129+
>
130+
visible
131+
</button>
132+
123133
<button
124134
type="button"
125135
onClick={() => {
@@ -143,6 +153,7 @@ const Demo = () => {
143153
style={{
144154
border: '1px solid red',
145155
boxSizing: 'border-box',
156+
display: visible ? null : 'none',
146157
}}
147158
>
148159
{(item, _, props) =>

src/Filler.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ const Filler: React.FC<FillerProps> = ({
4646

4747
return (
4848
<div style={outerStyle}>
49-
<ResizeObserver onResize={onInnerResize}>
49+
<ResizeObserver
50+
onResize={({ offsetHeight }) => {
51+
if (offsetHeight) {
52+
onInnerResize();
53+
}
54+
}}
55+
>
5056
<div
5157
style={innerStyle}
5258
className={classNames({

0 commit comments

Comments
 (0)