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

USWDS - In-page navigation: Exclude hidden headers #5393

Merged
merged 9 commits into from Aug 11, 2023

Conversation

amyleadem
Copy link
Contributor

@amyleadem amyleadem commented Jul 19, 2023

Summary

Updated JavaScript to exclude hidden headers from the in-page navigation link list. Any header with a style of display:none or visibility:hidden will now be excluded from the list of links in the component.

Note
This PR does not exclude headers hidden with usa-sr-only or a style of opacity: 0. The conversation surrounding this decision is in this comment, this comment, and this comment.

Warning
Both PR #5387 and this PR edit the same files and functions. We should expect merge conflicts.

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 with display:none or visibility: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:

  1. Install this branch
  2. Add component code for the in-page page navigation to a test page.
  3. Add h2 or h3 headers that are hidden with display: none or visibility:hidden styles to the main content region.
  4. Check that only the visible headers are included in the in-page nav link list

Additionally:

  • Confirm that this accounts for all expected hidden header scenarios
  • Confirm the code follows USWDS patterns
  • Confirm the test Storybook pages are useful, make sense, and are structured appropriately
  • Confirm no visual or behavioral regressions

@amyleadem amyleadem changed the title USWDS - In-page navigation: Add an option to designate the main content element USWDS - In-page navigation: Exclude hidden headers Jul 19, 2023
@amyleadem amyleadem marked this pull request as ready for review July 21, 2023 20:51
Copy link
Contributor

@mahoneycm mahoneycm left a 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 and visibility: 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?

Copy link
Contributor

@mejiaj mejiaj left a 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.

Comment on lines +61 to +62
headingStyle.getPropertyValue("display") !== "none" &&
headingStyle.getPropertyValue("visibility") !== "hidden";
Copy link
Contributor

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 account opacity: 0. This isn't a blocker to the main root of the issue.

Comment on lines 31 to 36
<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>
Copy link
Contributor

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.

Before
image

After
image

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>

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

packages/usa-in-page-navigation/src/index.js Show resolved Hide resolved
Copy link
Contributor Author

@amyleadem amyleadem left a 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.

Copy link
Contributor Author

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.

Comment on lines 31 to 36
<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>
Copy link
Contributor Author

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.

@amyleadem amyleadem requested a review from mejiaj August 4, 2023 22:29
@amyleadem
Copy link
Contributor Author

@mahoneycm
cc: @mejiaj
Thanks for starting the discussion on opacity: 0 and .usa-sr-only elements as possible candidates for inclusion here.

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 opacity:0, I lean away from including it because it feels like such a different method of hiding content. opacity:0 accepts user interaction, registers as a header in screen readers, takes up space, etc. Maybe it doesn't seem all that hidden to me? Definitely open to input on including this, but my gut is saying we shouldn't exclude these.

For .usa-sr-only, I can see that there is a case for including items with the left: -999em style. For context, we don't currently use it anywhere on <h2> or <h3> elements in our system and I am not sure how common it would be to use this directly on header elements. Do we want to include this style in our script?

@mejiaj
Copy link
Contributor

mejiaj commented Aug 7, 2023

@mahoneycm cc: @mejiaj Thanks for starting the discussion on opacity: 0 and .usa-sr-only elements as possible candidates for inclusion here.

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 opacity:0, I lean away from including it because it feels like such a different method of hiding content. opacity:0 accepts user interaction, registers as a header in screen readers, takes up space, etc. Maybe it doesn't seem all that hidden to me? Definitely open to input on including this, but my gut is saying we shouldn't exclude these.

For .usa-sr-only, I can see that there is a case for including items with the left: -999em style. For context, we don't currently use it anywhere on <h2> or <h3> elements in our system and I am not sure how common it would be to use this directly on header elements. Do we want to include this style in our script?

@amyleadem opacity and sr-only don't seem like requirements for this particular issue. We can always come back to it later based on user feedback.

I just noted for the record and to avoid duplicating testing efforts.

Copy link
Contributor

@mejiaj mejiaj left a 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.

@amyleadem amyleadem requested a review from mejiaj August 7, 2023 14:36
@amyleadem
Copy link
Contributor Author

@mejiaj I've updated the formatting on the file. Let me know if you need anything else!

Copy link
Contributor

@mahoneycm mahoneycm left a 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 and visibility: hidden are ignored by in page nav
  • Both storybook previews and local project testing worked as expected

Copy link
Member

@thisisdano thisisdano left a 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!

@thisisdano thisisdano merged commit 5024e14 into develop Aug 11, 2023
5 checks passed
@thisisdano thisisdano deleted the al-in-page-nav-hidden-header branch August 11, 2023 16:26
@thisisdano thisisdano mentioned this pull request Aug 18, 2023
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

Successfully merging this pull request may close these issues.

USWDS - Bug: In-page navigation pulls hidden headers
4 participants