fix: automatically scroll div down in history panel

This commit is contained in:
trafficlunar 2025-02-08 13:40:37 +00:00
parent 97ab9df328
commit d3c25422d4

View file

@ -16,9 +16,15 @@ const iconMap = {
function History() { function History() {
const { history, currentIndex, jumpTo } = useContext(HistoryContext); const { history, currentIndex, jumpTo } = useContext(HistoryContext);
const divRef = useRef<HTMLDivElement>(null);
useEffect(() => {
divRef.current?.scrollIntoView(false);
}, [history]);
return ( return (
<ScrollArea key={history.length} className="h-48 border border-zinc-200 dark:border-zinc-800 rounded-md"> <ScrollArea key={history.length} className="h-48 border border-zinc-200 dark:border-zinc-800 rounded-md">
<div className="flex flex-col"> <div ref={divRef} className="flex flex-col">
{history.map(({ name }, index) => { {history.map(({ name }, index) => {
const IconComponent = iconMap[name as keyof typeof iconMap]; const IconComponent = iconMap[name as keyof typeof iconMap];