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(doc-page): make markdown hashtag links scroll to elements properly #26

Closed
mesqueeb opened this issue Oct 14, 2020 · 0 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@mesqueeb
Copy link
Member

mesqueeb commented Oct 14, 2020

steps to reproduce:

  1. click on a link in the example section eg. like on https://blitzar.cycraft.co

Screenshot 2020-10-27 at 8 36 40

  1. observe that it doesn't work! :O

reason:

  • currently when a markdown link is written like so: [something](#some-chapter) it will push this on top of the main URL: blitzar.cycraft.co/#some-chapter

bad workaround:

  • in the markdown URLs I can write [something](/docs/blitz-form#some-chapter) instead.
  • this is less than ideal however, because it's ugly and prone to break when I change routing

desired fix:

  • fix to be implemented at: DocPage.vue
  • you may need to create a new test page that uses DocPage.vue in planetar/packages/dev to reproduce the issue and implement this fix more easily
  • have DocPage detect when all examples/sections are mounted. (I'm listening to some events to know about this already)
  • then scrape the DOM for all links in the markdown sections that start with #, and then attach an eventListener that does e.preventDefault() and e.stopPropagation()
  • use Quasar scroll utils to scroll to the element
  • the duration that it takes to have Quasar scroll to the element should be SCROLL_DURATION (do a global search for this in planetar)
  • after clicking a link and after the scroll is complete the hashtag scrolled to, should be added to the URL in the browser:
   /**
     * @param {MouseEvent} event
     */
    setUrlHash(event) {
      const activeTocHash = event.srcElement.getAttribute('href')
      const activeTocId = activeTocHash.replace('#', '')
      this.willBecomeActiveTocId = activeTocId
      this.activeTocId = ''
      setTimeout(() => {
        location.hash = activeTocId
      }, SCROLL_DURATION)
    },
  • this setUrlHash is also used by TOC.vue? so this logic should be in a planetar/packages/doc-builder/src/helpers/utils.ts file or something and imported into both TOC.vue and DocPage.vue
@mesqueeb mesqueeb transferred this issue from CyCraft/blitzar Oct 14, 2020
@mesqueeb mesqueeb changed the title fix(docs): make markdown hashtag links scroll to elements properly fix(doc-page): make markdown hashtag links scroll to elements properly Oct 14, 2020
@mesqueeb mesqueeb reopened this Oct 14, 2020
@mesqueeb mesqueeb added this to the release milestone Oct 16, 2020
@mesqueeb mesqueeb added the bug Something isn't working label Oct 17, 2020
@mesqueeb mesqueeb closed this as completed Jan 7, 2021
@mesqueeb mesqueeb assigned mesqueeb and unassigned AndrewKoch Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants