Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: navigation to correct heading in tools section #2790

Closed
wants to merge 14 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions components/tools/ToolsList.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import ToolsCard from './ToolsCard';
import Heading from '../typography/Heading'
import { useRef, useEffect } from 'react';
import Paragraph from '../typography/Paragraph'
export default function toolsList({ toolsData }) {
const categoryRefs = useRef({});

// Below UseEffect scrolls the page to a specific category referenced in the URL hash.
useEffect(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment, explaining about this useEffect block.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It scrolls the page to a specific category referenced in the URL hash.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akshatnema Done Sir

const hash = window.location.hash;
if (hash) {
Vishal2002 marked this conversation as resolved.
Show resolved Hide resolved
const decodedHash = decodeURIComponent(hash.slice(1));
const categoryRef = categoryRefs.current[decodedHash];
Vishal2002 marked this conversation as resolved.
Show resolved Hide resolved
if (categoryRef) {
categoryRef.scrollIntoView({ behavior: 'smooth', block: 'start'});
}
}
},[]);

return (
<div className="" data-testid="ToolsList-main" >
<div data-testid="ToolsList-main" className="max-h-screen overflow-y-auto" >
{Object.keys(toolsData).map((categoryName, index) => {
if(toolsData[categoryName].toolsList.length > 0) return (
<div className='my-8' key={index} id={categoryName}>
<div className='my-8' key={index} id={categoryName} ref={el => categoryRefs.current[categoryName] = el}>
<Heading typeStyle='heading-md-semibold' className='my-2' >
{categoryName}
</Heading>
Expand Down
Loading