Skip to content

fix: skip-to-content scroll behavior - #2401

Merged
sy-records merged 3 commits into
developfrom
fix-skip-link-scroll
Apr 17, 2024
Merged

fix: skip-to-content scroll behavior#2401
sy-records merged 3 commits into
developfrom
fix-skip-link-scroll

Conversation

@jhildenbiddle

@jhildenbiddlejhildenbiddle commented Apr 11, 2024

Copy link
Copy Markdown
Member

Summary

Fixes an issue the new (unreleased) "Skip to Content" link that caused an immediate jump to to the content (instead scrolling) and the main content to scroll down (instead of being static) into place.

Example of bug (develop branch preview w/ Chrome 123)

The incorrect behavior is the result of three separate things occurring at the same time:

  1. By default, browsers will automatically scroll any offscreen element that receives focus into view. This is the correct behavior for accessibility purposes because the focused item should be in view.
  2. Clicking the "Skip to Content" link places the focus on the main content area. This is the correct behavior for accessibility purposes because the focused item should be in view. However, by placing the focus on an off-screen element, the browser's default behavior (see above) causes the scroll position to jump to the content instead of smoothly scrolling to it.
  3. Docsify's "smooth scroll" behavior aligns the main content container element to the top edge of the viewport.
Example-Bug.mp4

Example of fix (PR changes w/ Chrome 123)

The fix if simple thanks to modern APIs: set the preventScroll option to true when calling the browser's native focus() method:

Example-fix.mp4

Related issue, if any:

None

What kind of change does this PR introduce?

Bugfix

For any code change,

N/A

Does this PR introduce a breaking change?

No

Tested in the following browsers:

  • Chrome
  • Firefox
  • Safari

@vercel

vercelBot commented Apr 11, 2024

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

NameStatusPreviewCommentsUpdated (UTC)
docsify-preview✅ Ready (Inspect)Visit Preview💬 Add feedbackApr 17, 2024 5:57am

@jhildenbiddlejhildenbiddle added this to the 5.x milestone Apr 11, 2024
@jhildenbiddlejhildenbiddle self-assigned this Apr 11, 2024
@jhildenbiddle
jhildenbiddle requested a review from a teamApril 12, 2024 14:17
@Koooooo-7

Koooooo-7 commented Apr 13, 2024

Copy link
Copy Markdown
Member

Hi @jhildenbiddle , could plz more details on it? (Much thx that if you could provide a screenshot/recording)
sorry, that I don't full understand the behaviors.

As per the early discuss and my understanding, thats what I did:
I open 2 preview, with and without this fix.

On the preview site, press Tab, click the Skip to content is fine.
Then, I tabs Tab multi times, and click or switch sections.

@jhildenbiddle

jhildenbiddle commented Apr 15, 2024

Copy link
Copy Markdown
MemberAuthor

@Koooooo-7 --

I've added descriptions and videos demonstrating the bug and the fix to PR summary (above).

@Koooooo-7Koooooo-7 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, and nice experience improvement.

@sy-recordssy-records left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Good job!

Sign up for freeto 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.

3 participants

@jhildenbiddle@Koooooo-7@sy-records