Skip to content

Commit 8185cd9

Browse files
authored
Merge pull request #1785 from AletheiaFact/Correct-toggle-section
Fixing the Toggle Section button
2 parents 93182f5 + 35770c4 commit 8185cd9

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/components/Claim/ClaimView.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { currentUserRole } from "../../atoms/currentUser";
1818
import { useAtom } from "jotai";
1919

2020
const ClaimView = ({ personality, claim, href, hideDescriptions }) => {
21-
const [isAffixed, setIsAffixed] = useState(true);
21+
const [isAffixed, setIsAffixed] = useState(false);
2222
const ref = useRef<HTMLDivElement | null>(null);
2323
const dispatch = useDispatch();
2424
const { t } = useTranslation();
@@ -44,19 +44,24 @@ const ClaimView = ({ personality, claim, href, hideDescriptions }) => {
4444
}, [claim, claimContent, dispatch, isImage, personality, t]);
4545

4646
useEffect(() => {
47-
const handleScroll = () => {
4847
if (!ref.current) return;
49-
50-
const { bottom } = ref.current.getBoundingClientRect();
51-
const windowHeight = window.innerHeight;
52-
53-
if (bottom > windowHeight) {
54-
setIsAffixed(true);
55-
} else {
56-
setIsAffixed(false);
48+
49+
const scrollableSpeech = ref.current.scrollHeight > window.innerHeight;
50+
if (scrollableSpeech) {
51+
setIsAffixed(true);
5752
}
58-
};
59-
window.addEventListener("scroll", handleScroll);
53+
54+
const handleScroll = () => {
55+
const { bottom } = ref.current.getBoundingClientRect();
56+
const isFixed = bottom > window.innerHeight;
57+
58+
if (isFixed) {
59+
setIsAffixed(true);
60+
} else {
61+
setIsAffixed(false);
62+
}
63+
};
64+
window.addEventListener("scroll", handleScroll);
6065
}, []);
6166

6267
return (

0 commit comments

Comments
 (0)