-
-
Notifications
You must be signed in to change notification settings - Fork 681
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: fixed links to specific category in tools section #2190
Changes from 8 commits
290f3f6
6a0e589
428050b
de3ce8c
51f399d
e8cc15d
1fc1864
8b53296
51eb9f2
e30ac6e
aebbb69
d08cb6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -48,6 +48,18 @@ export default function ToolDashboard() { | |||||||
}, 1000); | ||||||||
}, []); | ||||||||
|
||||||||
// useEffect to scroll particular div into view | ||||||||
useEffect(() => { | ||||||||
setTimeout(() => { | ||||||||
const path = router?.asPath | ||||||||
const id = path?.slice(path?.indexOf("#") + 1).replace("%20", " ") | ||||||||
const element = document.getElementById(id) | ||||||||
if (element) { | ||||||||
element.scrollIntoView({ behavior: 'smooth', block: "nearest", inline: "nearest" }) | ||||||||
} | ||||||||
}, 1000) | ||||||||
}, []) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Kindly add a spacing to make it more readable inside codebase (since they are 2 different sections of code). |
||||||||
|
||||||||
// useEffect function to enable the close Category dropdown Modal feature when clicked outside of the modal | ||||||||
useEffect(() => { | ||||||||
const checkIfClickOutside = (e) => { | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ export default function toolsList({ toolsData }) { | |
<div className="" data-testid="ToolsList-main" > | ||
{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 scroll-m-[100px]' key={index} id={categoryName}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use units in |
||
<Heading typeStyle='heading-md-semibold' className='my-2' > | ||
{categoryName} | ||
</Heading> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using
id
attribute, can't we useref
here to add the behavior?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can think about this, but the "Jump to Category" dropdown already uses the "id" of each div to scroll to, so wouldn't it be better to use the same strategy for initial scrolling as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually access the DOM elements directly in react. React has it's own virtual DOM feature which enables better performance on the website. That's why I asked to use ref in this case. We used
id
just to reference the category and link it in dropdown.