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

SkipLink double jumps to first heading then #maincontent if disableDefaultBehaviour is not set #166

Open
waringr opened this issue Apr 25, 2023 · 1 comment

Comments

@waringr
Copy link

waringr commented Apr 25, 2023

Currently if the SkipLink is included without any additional attributes, and there is an element on the page with an id of maincontent, then clicking the skip to content link causes a double jump, first to the heading, then to #maincontent.

A suggested fix would be to always call e.preventDefault, then jump to either the first heading or #maincontent based on the setting of disableDefaultBehaviour and the existence of the id, e.g.

e.preventDefault()
if(!disableDefaultBehaviour && document.getElementById('maincontent')) {
  this.focusElement(document.getElementById('maincontent'))
} else {
  this.focusElement(/* first heading*/)
}
@KaiSpencer
Copy link
Contributor

Interesting discussion I will link in around the original motivation on the focus of h1.

nhsuk/nhsuk-frontend#864 (comment)

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

No branches or pull requests

2 participants