|
1 | | -import { useEffect, useMemo, useState } from "react"; |
| 1 | +import { useEffect, useMemo, useState, useRef } from "react"; |
2 | 2 | import { useBoolean } from "@fluentui/react-hooks" |
3 | 3 | import { FontIcon, Stack, Text } from "@fluentui/react"; |
4 | 4 |
|
@@ -29,14 +29,17 @@ export const Answer = ({ |
29 | 29 |
|
30 | 30 | const parsedAnswer = useMemo(() => parseAnswer(answer), [answer]); |
31 | 31 | const [chevronIsExpanded, setChevronIsExpanded] = useState(isRefAccordionOpen); |
32 | | - |
| 32 | + const refContainer = useRef<HTMLDivElement>(null); |
33 | 33 | const handleChevronClick = () => { |
34 | 34 | setChevronIsExpanded(!chevronIsExpanded); |
35 | 35 | toggleIsRefAccordionOpen(); |
36 | 36 | }; |
37 | 37 |
|
38 | 38 | useEffect(() => { |
39 | 39 | setChevronIsExpanded(isRefAccordionOpen); |
| 40 | + if(chevronIsExpanded && refContainer.current){ |
| 41 | + refContainer.current.scrollIntoView({ behavior:'smooth'}); |
| 42 | + } |
40 | 43 | }, [isRefAccordionOpen]); |
41 | 44 |
|
42 | 45 | const createCitationFilepath = (citation: Citation, index: number, truncate: boolean = false) => { |
@@ -104,11 +107,11 @@ export const Answer = ({ |
104 | 107 |
|
105 | 108 | </Stack> |
106 | 109 | {chevronIsExpanded && |
107 | | - <div style={{ marginTop: 8, display: "flex", flexDirection: "column", height: "100%", gap: "4px", maxWidth: "100%" }}> |
| 110 | + <div ref={refContainer} style={{ marginTop: 8, display: "flex", flexDirection: "column", height: "100%", gap: "4px", maxWidth: "100%" }}> |
108 | 111 | {parsedAnswer.citations.map((citation, idx) => { |
109 | 112 | return ( |
110 | 113 | <span title={createCitationFilepath(citation, ++idx)} key={idx} onClick={() => onCitationClicked(citation)} className={styles.citationContainer}> |
111 | | - <div className={styles.citation}>{idx}</div> |
| 114 | + <div className={styles.citation} key={idx}>{idx}</div> |
112 | 115 | {createCitationFilepath(citation, idx, true)} |
113 | 116 | </span>); |
114 | 117 | })} |
|
0 commit comments