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
USWDS - In-Page Navigation: Fix error when clicking link starting with number #5200
USWDS - In-Page Navigation: Fix error when clicking link starting with number #5200
Conversation
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.
This works like a charm!
Tested:
- Added numbers to the start of headings in the storybook preview
- Clicked through in-page navigation to confirm it scrolled to the correct heading
- Confirmed no errors in the console
- Logged
document.getElementById(el.hash.slice(1))
and confirmed the correct element was being selected. - Ran gulp test for in-page navigation
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.
Thanks for the PR! I think it would be useful to add it to the twig template for Storybook.
Tested:
- Component works as expected in StorybookJS
- No issues in unit test
Didn't mean to edit your comment Charlie, sorry!
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.
Good improvement. Thank you!
Works as expected when headings have a numeric prefix in Safari, Edge, Chrome, Firefox.
I agree that it would be great to see an example of this reflected in the Storybook twig template.
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.
Nice clean solution
Summary
Fix an error when clicking a link starting with a number. Certain links would not scroll as expected when clicked.
Related issue
Fixes #5199
Problem statement
See #5199
Solution
This implements the first of the proposed options outlined at #5199 (comment) .
This has a few advantages, in that it limits the scope of the changes and maintains backwards compatibility. The only downside that I can consider is that these IDs are still technically not valid for use as CSS selectors, in case someone would need to reference it as such. As demonstrated in the included tests, a workaround is to reference the ID as using an attribute selector (e.g.
[id="1-installation"]
).Testing and review