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

[IDP] In-page navigation #4918

Merged
merged 58 commits into from
Nov 8, 2022
Merged

[IDP] In-page navigation #4918

merged 58 commits into from
Nov 8, 2022

Conversation

mitchmoccia
Copy link
Contributor

This is a follow-up PR for In-page navigation from this earlier PR:
#4860

https://federalist-3b6ba08e-0df4-44c9-ac73-6fc193b0e19c.app.cloud.gov/preview/uswds/uswds/mm-in-page-nav4/?path=/story/components-in-page-navigation--default

This version addresses all the great comments left by @mejiaj. Looking forward to any and all feedback, thank you!

@amyleadem
Copy link
Contributor

@mitchmoccia Starting to do some testing on appearance and behavior - it is working well so far! I had a few questions about alignment and am flagging some questions in the code comments. I will keep looking poking at it this afternoon and will cycle back tomorrow for more review. If you have any questions in the meantime, please let me know!

{% endif %}
</main>

<aside class="usa-in-page-nav"></aside>
Copy link
Contributor

Choose a reason for hiding this comment

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

@mitchmoccia @mejiaj
Wondering about the benefits of nesting the <nav> inside an <aside>. I believe it is valid (depending on how it is defined), but feels semantically unnecessary and appears to just add an extra layer for users to tab through.

Can we just make this element the <nav> itself or switch to a <div> (if it needs a wrapper)?

Copy link
Contributor

Choose a reason for hiding this comment

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

The HTML5 standard mentions [html.spec.whatwg.org]:

The element can be used for typographical effects like pull quotes or sidebars, for advertising, for groups of nav elements, and for other content that is considered separate from the main content of the page.

And they have an example below (third example down):

image

TL;DR I can see both sides of the argument. Semantically I think it's okay. The final decision depends on the screen reader experience. Unless others understand the use case better, please chime in!

Copy link
Contributor

@amyleadem amyleadem Aug 18, 2022

Choose a reason for hiding this comment

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

Makes sense!
Something I noticed is that in the same spec, it does show this example for the nav element. https://html.spec.whatwg.org/multipage/sections.html#the-nav-element

In the following example, there are two nav elements, one for primary navigation around the site, and one for secondary navigation around the page itself.

image

FWIW: I did poke around at other implementations and found that in its own implementation of a similar component (The "In this article" TOC on the right), Mozilla uses an <aside> with a nested <section> and no <nav>: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/aside

Other popular design systems use <nav> with a nested list or just a <div> with a nested list.

So my tl;dr is that it seems like there are a lot of possible correct paths here regarding if it is a nav or aside (or both), and that it might just depend on how we define "tangential" or "indirectly related" content. Users should still be able to find what they need with either. Change would only be needed here if we want to remove an extra layer when users navigate by element, but it shouldn't affect users who tab into it.

Reference:

The aside element represents a section of a page that consists of content that is tangentially related to the content around the aside element, and which could be considered separate from that content. Such sections are often represented as sidebars in printed typography.

The element can be used for typographical effects like pull quotes or sidebars, for advertising, for groups of nav elements, and for other content that is considered separate from the main content of the page.

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 the tag team analysis!! I did some quick testing in VoiceOver and it doesn't seem to make a difference... I did make the decision to use aside > nav based on the w3c example but will go with whatever makes most sense.

mejiaj
mejiaj previously requested changes Aug 18, 2022
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.

Very nice rewrite @mitchmoccia! The code, but JS especially looks much more in-line with other component standards.

Added some comments and suggestions. Also, I'm sure you've got this in mind already, but I didn't notice any unit tests for this component.

packages/usa-in-page-navigation/src/index.js Outdated Show resolved Hide resolved
packages/usa-in-page-navigation/src/index.js Show resolved Hide resolved
},
keydown: {
[IN_PAGE_NAV_LINK]: keymap({
Enter: handleEnterFromLink,
Copy link
Contributor

Choose a reason for hiding this comment

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

Triggering via spacebar might also be a good idea, not a requirement though.

Copy link
Member

Choose a reason for hiding this comment

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

Let's consider this as a possible followup enhancement.

Copy link
Contributor

Choose a reason for hiding this comment

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

Created issue #5021.

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

Amazing feedback @amyleadem and @mejiaj THANK YOU... I'll be addressing all of these ASAP

@thisisdano thisisdano changed the title In-page navigation complete rewrite [IDP] In-page navigation Nov 2, 2022
@thisisdano thisisdano changed the base branch from develop to idp-staging November 2, 2022 05:16
@mitchmoccia
Copy link
Contributor Author

@thisisdano @mejiaj @amyleadem Just made a great update per Dan's suggestion... The in-page nav heading text and heading level are now customizable from the HTML via data attributes! The new attributes are data-title and data-heading-level both added to the aside element.

I have also updated the unit tests and everything is looking good. Let me know how it looks on your end, thanks!

@mitchmoccia
Copy link
Contributor Author

I added two variables const
IN_PAGE_NAV_TITLE = “On this page”;
IN_PAGE_NAV_HEADING_LEVEL = “h4"

and then check for the presence of the corresponding data attributes and if none, use the defaults...

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.

Some great improvements here! Added some comments and questions.

I tested the for:

  • ANDI a11y plugin - no errors
  • AXE plugin - no errors
  • Checked display on site - minor with empty <p></p>
  • Checked output HTML of component - minor with empty <p></p>
  • Tested custom data attributes for heading
  • Reviewed JS for issues and possible improvements
  • SASS formatting and possible improvements
  • Ran NPM test - It seems only in-page nav tests ran

image

Seeing the same in CircleCI build.
image

@thisisdano thisisdano dismissed stale reviews from amyleadem and mejiaj November 8, 2022 19:00

Addressed changes

@thisisdano thisisdano merged commit 3155040 into idp-staging Nov 8, 2022
@thisisdano thisisdano deleted the mm-in-page-nav4 branch November 8, 2022 19:31
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.

4 participants