Auto-scroll to the opened category

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-04-08 07:57:52 -07:00
parent 95d0fc5303
commit a16ffbc1f4

View File

@@ -137,6 +137,19 @@ function MitigationListContent({
return initialHashCategory ? [initialHashCategory] : [];
});
// Scroll to expanded category when page loads with a category in the fragment
useEffect(() => {
if (initialHashCategory) {
// Small delay to ensure the DOM is fully rendered
setTimeout(() => {
const element = document.getElementById(initialHashCategory);
if (element) {
element.scrollIntoView({ behavior: "smooth", block: "start" });
}
}, 100);
}
}, [initialHashCategory]);
// Listen for hash changes (like when using back button)
useEffect(() => {
const handleHashChange = () => {
@@ -468,6 +481,7 @@ function MitigationListContent({
return (
<div
key={category.id}
id={category.id}
className="border rounded-lg overflow-hidden"
>
<Card className="border-0 shadow-none">