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: pagemenu conditional section scrolling issues #322

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

marcellmueller
Copy link
Contributor

@marcellmueller marcellmueller commented Feb 4, 2025

Follow up for a couple of bugs introduced in #157, I noticed in pages without closures if you scroll down and then scroll back up the top selection in the page menu won't highlight. This is due to the conditional section ref not being in the page.

  • added the missing closures menu 🤦
  • refactored the menu array to better handle conditional sections
Screenshot 2025-02-04 at 10 09 28 AM

@marcellmueller marcellmueller force-pushed the fix/pagemenu-conditionals branch 2 times, most recently from 57bcebb to 104922d Compare February 6, 2025 17:10
@@ -50,7 +50,7 @@ const PageMenu: React.FC<PageMenuProps> = ({
(section) => section.sectionIndex === Number(index),
);
if (selectedSection) {
window.location.hash = selectedSection.link;
window.location.hash = selectedSection.href;
Copy link
Contributor

Choose a reason for hiding this comment

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

(bug):

  1. We need to use encodeURIComponent for Safety. If href contains special characters i.e. spaces, &, ? it will prevent encoding URL issues.

  2. We only need to update the hash if it actually changes. This will improve performance. We can do something like this

if (selectedSection?.href && window.location.hash !== `#${selectedSection.href}`) {
  window.location.hash = encodeURIComponent(selectedSection.href);
}

isThingsToDo ? thingsToDoRef : null,
contactRef,
].filter((ref) => !!ref),
[description, isClosures, isThingsToDo],
Copy link
Contributor

Choose a reason for hiding this comment

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

(question): sectionRefs depends on closuresRef, siteDescriptionRef, but they are missing from dependencies array. Should that be included?

@marcellmueller marcellmueller force-pushed the fix/pagemenu-conditionals branch from 104922d to fd9b140 Compare February 6, 2025 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants