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: Exclude hidden headers #5393
Conversation
- Align testing technique with content selector test in #5387
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 is a great enhancement!
- Confirmed prior existence of bug
- Headers with
display: none
andvisibility: hidden
are ignored by in page nav - Both storybook previews and local project testing worked as expected
I considered sr-only
classes and opacity: 0
as other methods of hiding headers. In both of these examples, the element is still accessible and interactable. In these cases, I believe it might make sense to allow these to be targeted by the in-page navigation.
Do you have any thoughts on these methods of hiding headers?
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 work, no issues with functionality.
I've some suggestions for improving clarity in the templates.
headingStyle.getPropertyValue("display") !== "none" && | ||
headingStyle.getPropertyValue("visibility") !== "hidden"; |
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.
Note
As mentioned in comments. This doesn't take into accountopacity: 0
. This isn't a blocker to the main root of the issue.
packages/usa-in-page-navigation/src/test/test-patterns/test-hidden-headers.twig
Show resolved
Hide resolved
<h2>This heading is visible</h2> | ||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. </p> | ||
<h3>This heading is visible</h3> | ||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. </p> | ||
<h2 style="display:none">This heading is hidden with display:none</h2> | ||
<h2 style="visibility:hidden">This heading is hidden with visibility:hidden</h2> |
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.
Optional
To improve clarity you could add some styles to the hidden elements. Example below.
Here's the markup I used:
<div class="outline-2px outline-magenta padding-1" style="outline-style: dashed;">
<pre>Display: none;</pre>
<h2 style="display:none">This heading is hidden with display:none</h2>
</div>
<div class="outline-2px outline-magenta padding-1" style="outline-style: dashed;">
<pre>Visibility: hidden;</pre>
<h2 style="visibility:hidden">This heading is hidden with visibility:hidden</h2>
</div>
<div class="outline-2px outline-magenta padding-1" style="outline-style: dashed;">
<pre>Opacity: 0;</pre>
<h2 style="opacity: 0;">This heading is hidden with opacity:0;</h2>
</div>
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.
Love this idea. Added in a420068.
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.
Are the new checks necessary? I couldn't get them to trigger. It also seems like we're adding test behaviors to default component.
If we re-used this template for testing ― that'd be okay. But we already have a separate test 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.
Oof - I feel like you caught me in my mess! Looks like I accidentally left some old code in this PR. Thanks for watching my back and catching it. Removed in 39d6835.
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 keen eye on this one @mejiaj! I appreciate the suggestion for the improved test and that you flagged the old code.
I believe I have addressed all of your concerns. Let me know if you have any questions or comments.
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.
Oof - I feel like you caught me in my mess! Looks like I accidentally left some old code in this PR. Thanks for watching my back and catching it. Removed in 39d6835.
<h2>This heading is visible</h2> | ||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. </p> | ||
<h3>This heading is visible</h3> | ||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. </p> | ||
<h2 style="display:none">This heading is hidden with display:none</h2> | ||
<h2 style="visibility:hidden">This heading is hidden with visibility:hidden</h2> |
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.
Love this idea. Added in a420068.
packages/usa-in-page-navigation/src/test/test-patterns/test-hidden-headers.twig
Show resolved
Hide resolved
@mahoneycm Are we comfortable moving forward with how it is now, or should we try to include these in the script as well? This might be easier in an in-person discussion, but I can see both sides to this. For For |
@amyleadem opacity and I just noted for the record and to avoid duplicating testing efforts. |
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.
Just a comment on spacing in test template, otherwise LGTM.
packages/usa-in-page-navigation/src/test/test-patterns/test-hidden-headers.twig
Show resolved
Hide resolved
@mejiaj I've updated the formatting on the file. Let me know if you need anything else! |
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 gets my stamp of approval! Thank you for sharing your thoughts on the opacity and sr-only headers! In both situations they are still interactable so I believe we're good to move forward without including them in this work 👍
- Confirmed prior existence of bug
- Headers with
display: none
andvisibility: hidden
are ignored by in page nav - Both storybook previews and local project testing worked as expected
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.
Thoughtful and implemented with care!
Summary
Updated JavaScript to exclude hidden headers from the in-page navigation link list. Any header with a style of
display:none
orvisibility:hidden
will now be excluded from the list of links in the component.Breaking change
This is not a breaking change.
Related issue
Closes #5392
Related pull requests
Changelog PR
Preview link
Preview link: In-page navigation
Problem statement
The in-page navigation component pulls hidden headers from the main content region. These should be excluded from the component link list.
Solution
The
getSectionHeadings
function now filters through the array of section headings and removes any headers that are styled withdisplay:none
orvisibility:hidden
.Testing and review
To test in Storybook:
Open the Hidden Headers test page and confirm that only the visible headers are included in the in-page navigation link list.
To test in a local project:
display: none
orvisibility:hidden
styles to themain
content region.Additionally: