Skip to content

Commit 946ff62

Browse files
committed
feat: rename sticky to persistentIndices
1 parent c483127 commit 946ff62

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/VirtualList.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type Props<ITEM> = {
1818
buffer?: number,
1919
items: ITEM[],
2020
renderItem: (item: ITEM, index: number) => ReactNode,
21-
sticky?: number[], // index[]
21+
persistentIndices?: number[], // index[]
2222
className?: string,
2323
style?: React.CSSProperties,
2424
} & OptionalKeys<typeof defaultProps>
@@ -65,8 +65,8 @@ export const VirtualList = forwardRef(function <ITEM>(
6565
endIndex = count - Math.floor(bottomSpace / itemSize)
6666
}
6767
const mainVisibleIndexes = Array.from({ length: endIndex - startIndex }, (_, index) => index + startIndex);
68-
let visibleIndexes = mainVisibleIndexes.concat(props.sticky || [])
69-
if (props.sticky?.length) {
68+
let visibleIndexes = mainVisibleIndexes.concat(props.persistentIndices || [])
69+
if (props.persistentIndices?.length) {
7070
visibleIndexes = [...new Set(visibleIndexes)].sort((a, b) => a - b)
7171
}
7272
const visible = visibleIndexes.map(i => props.items[i])

src/examples/sticky.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ export default function StickyExample() {
55
return <>
66
<h2>Sticky</h2>
77
<ul>
8-
<li>"sticky" support multiple items.</li>
8+
<li>Use prop 'persistentIndices' to make items persistent.</li>
9+
<li>"persistentIndices" support multiple items.</li>
10+
<li>Use css 'position:sticky' make items sticky.</li>
911
</ul>
1012
<VirtualList
1113
items={exampleData}
1214
style={{ height: '600px', border: '1px solid #ccc', padding: '10px' }}
13-
sticky={[1]} // sticky the second item
15+
persistentIndices={[1]} // sticky the second item
1416
renderItem={(item, index) => <div key={index} style={{ marginBottom: '10px', ...index === 1 && { position: 'sticky', top: 0, background: '#fff', zIndex: 2 } }}>
1517
<h3>{index}. {item.headline}</h3>
1618
<div>

0 commit comments

Comments
 (0)