fix header name on unloaded row render

This commit is contained in:
jeffvli
2026-02-09 14:11:07 -08:00
parent 95dee5f4ee
commit 9f73cfdda1
@@ -866,22 +866,30 @@ export const ItemDetailList = ({
const headerLeftRef = useRef<HTMLSpanElement>(null); const headerLeftRef = useRef<HTMLSpanElement>(null);
const dataSourceRef = useRef(dataSource); const dataSourceRef = useRef(dataSource);
dataSourceRef.current = dataSource; dataSourceRef.current = dataSource;
const lastHeaderNameRef = useRef('');
const handleRowsRendered = useCallback( const handleRowsRendered = useCallback(
(range: { startIndex: number; stopIndex: number }) => { (range: { startIndex: number; stopIndex: number }) => {
const el = headerLeftRef.current; const el = headerLeftRef.current;
if (el) { if (el) {
const album = dataSourceRef.current[range.startIndex] as Album | undefined; const album = getItem?.(range.startIndex) as Album | undefined;
const name = album?.name ?? ''; const name = album?.name ?? '';
if (name) {
lastHeaderNameRef.current = name;
el.textContent = name; el.textContent = name;
el.setAttribute('data-title', name); el.setAttribute('data-title', name);
el.title = name; el.title = name;
} else {
el.textContent = lastHeaderNameRef.current;
el.setAttribute('data-title', lastHeaderNameRef.current);
el.title = lastHeaderNameRef.current;
}
} }
if (onRangeChanged) { if (onRangeChanged) {
onRangeChanged(range); onRangeChanged(range);
} }
}, },
[onRangeChanged], [getItem, onRangeChanged],
); );
const throttledHandleRowsRendered = useMemo( const throttledHandleRowsRendered = useMemo(