codeforpdx / PASS

PASS project - with HMIS module integration
MIT License
26 stars 25 forks source link

Bug: Different heading levels used for styling purposes instead of semantically on the home page #456

Closed milofultz closed 8 months ago

milofultz commented 9 months ago

Bug Description:

Heading levels are used in ways to affect their styling and not being used semantically. This leads to poor experiences for users of assistive technologies. See MDN's notes on navigation using headings.


Reproduction Steps:

1. Go to the home page and turn on your screen reader (Voiceover, in this instance). 2. Go to the list of headings (using the rotor in Voiceover) 3. Note that they are not linear (e.g. 2, 5, 2, 5; instead of 2, 3, 2, 3)

What should be expected is a linear tree of heading levels. Each child should be a direct descendant of the parent (e.g. an <h2> element can only have succeeding <h3>s as direct children).

Screenshots (If applicable):

Screen Shot 2023-10-13 at 4 55 53 PM Screen Shot 2023-10-13 at 4 55 55 PM Screen Shot 2023-10-13 at 4 55 57 PM Screen Shot 2023-10-13 at 4 56 00 PM

Screenshots are from this extension.

Possible Solution (optional):

Use CSS to style elements using something like a class name or the tag name itself (for example, .subheader or applied directly to h2) and modify this based on zoom level, width of browser, etc.

This would likely mean we need to decouple our styling from the MUI Typography component. Unsure how this is done, but I see the sx prop.

Thinking it would probably make sense to either make components that are styled correctly that we can then apply a heading level to, or something of that nature, to make a more modular and more easily maintained structure (if these styles are only used in small parts of the app, I don't want to go full design system and build out unnecessary infra).

timbot1789 commented 9 months ago

Nice catch. You're right that we can override any MUI styles with the sx property. If that's not sufficient to fix the accessibility issues, we may want to take a look at base-ui, which advertises itself as an accessible library.

It looks like, at least for the home screen, the issue is with our own styles. We're hard-coding the h2 and h5 values. We can switch those over to more semantic ones pretty easily, and move font sizes to visual CSS styles.

xscottxbrownx commented 9 months ago

@milofultz - I completely understand the semantic linear idea, but what I have confusion on is where do you have to start?

Do you always have to start with <h1>?

Answers to this and I can get started on this issue.


@timbot1789 as well,

MUI makes it much easier to do what we want to do here.

If you want the text to look stylistically like an h1, but need it to be an h2 semantically:

<Typography variant="h1" component="h2">
  h1. Heading
</Typography>
milofultz commented 9 months ago

@milofultz - I completely understand the semantic linear idea, but what I have confusion on is where do you have to start?

Do you always have to start with <h1>?

Answers to this and I can get started on this issue.

You usually only want a single h1 on the page. From MDN:

While using multiple <h1> elements on one page is allowed by the HTML standard (as long as they are not nested), this is not considered a best practice. A page should generally have a single <h1> element that describes the content of the page (similar to the document's element</a>).</p> </blockquote> <p>As far as what needs to be done, it's mainly just ensuring that the headers follow that linear structure. See the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements#nesting">nesting example on MDN</a> as an example of how things should be stacked. </p> <p>Another example, think of it as a "belongs to" relationship. </p> <ul> <li>We have an <code>h2</code> of "Food"</li> <li>another heading of "Fruit" would "belong to" the <code>h2</code> of "Food", and because it is a direct descendant, it would <em>have</em> to be an <code>h3</code>.</li> <li>"Apples" would also "belong to" the "Fruit" <code>h3</code> and because it is a direct descendant, it would be an <code>h4</code>.</li> <li>"Vegetables" would be an <code>h3</code> because it is the same level as/a sibling of "Fruit" and also a direct descendant of "Food". </li> <li>etc. etc.</li> </ul> <p>Think of them as structural items that help organize the content and you should be gucci 👍 </p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/xscottxbrownx"><img src="https://avatars.githubusercontent.com/u/71395931?v=4" />xscottxbrownx</a> commented <strong> 9 months ago</strong> </div> <div class="markdown-body"> <blockquote> <blockquote> <p>@milofultz - I completely understand the semantic linear idea, but what I have confusion on is where do you have to start? Do you always have to start with <code><h1></code>? Answers to this and I can get started on this issue.</p> </blockquote> <p>You usually only want a single <code>h1</code> on the page. <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements#avoid_using_multiple_h1_elements_on_one_page">From MDN</a>:</p> <blockquote> <p>While using multiple <code><h1></code> elements on one page is allowed by the HTML standard (as long as they are not <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements#nesting">nested</a>), this is not considered a best practice. A page should generally have a single <code><h1></code> element that describes the content of the page (similar to the document's <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title"><title> element</a>).</p> </blockquote> <p>As far as what needs to be done, it's mainly just ensuring that the headers follow that linear structure. See the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements#nesting">nesting example on MDN</a> as an example of how things should be stacked.</p> <p>Another example, think of it as a "belongs to" relationship.</p> <ul> <li>We have an <code>h2</code> of "Food"</li> <li>another heading of "Fruit" would "belong to" the <code>h2</code> of "Food", and because it is a direct descendant, it would <em>have</em> to be an <code>h3</code>.</li> <li>"Apples" would also "belong to" the "Fruit" <code>h3</code> and because it is a direct descendant, it would be an <code>h4</code>.</li> <li>"Vegetables" would be an <code>h3</code> because it is the same level as/a sibling of "Fruit" and also a direct descendant of "Food".</li> <li>etc. etc.</li> </ul> <p>Think of them as structural items that help organize the content and you should be gucci 👍</p> </blockquote> <p>understand all this completely. What I am asking is if an h1 HAS to be on every page, or can you start from any header level (like h2 or h3 for example) and work down linearly?</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/xscottxbrownx"><img src="https://avatars.githubusercontent.com/u/71395931?v=4" />xscottxbrownx</a> commented <strong> 9 months ago</strong> </div> <div class="markdown-body"> <blockquote> <p>understand all this completely. What I am asking is if an h1 HAS to be on every page, or can you start from any header level (like h2 or h3 for example) and work down linearly?</p> </blockquote> <p>Found it in <code>usage notes</code>, yes start from <code>h1</code></p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/milofultz"><img src="https://avatars.githubusercontent.com/u/65684361?v=4" />milofultz</a> commented <strong> 9 months ago</strong> </div> <div class="markdown-body"> <p>Ah @xscottxbrownx , not trying to mansplain at you, my apologies. Let me know if you have any more questions</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/xscottxbrownx"><img src="https://avatars.githubusercontent.com/u/71395931?v=4" />xscottxbrownx</a> commented <strong> 9 months ago</strong> </div> <div class="markdown-body"> <p>@milofultz have one more question for you...</p> <p>Do you have any suggestions for pages that don't logically have an <code>h1</code>? Like for instance our <code>Contacts</code> page, or this <code>Home</code> page? The docs say to always start from an <code>h1</code>.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/milofultz"><img src="https://avatars.githubusercontent.com/u/65684361?v=4" />milofultz</a> commented <strong> 9 months ago</strong> </div> <div class="markdown-body"> <p>@xscottxbrownx There should always be an <code>h1</code> for assistive technologies to have the proper hierarchy and know the content, but this <code>h1</code> can be made invisible so it's only for assistive technologies. It should identify and describe the main content of the page. For "Home" and possibly for "Contacts", I'd reckon it's probably the same as the <code>title</code> of the page? For the case of "Contacts", an <code>h1</code> of "Contacts" would probably suffice, or more if context is needed.</p> <p>See <a href="https://accessibleweb.com/question-answer/does-the-tag-on-a-page-need-to-be-visible-to-the-eye-and-to-screen-readers/">this page for an example</a>:</p> <blockquote> <p>Should an <code><h1></code> tag be used in this manner, it should be written in HTML before the main content of the page. Screen reader users can utilize the level one heading as a means to skip to the page header (similar to how a skip to content link navigates to the main content of the page). The <code><h1></code> tag should not be hidden from the <a href="https://accessibleweb.com/question-answer/what-is-an-accessibility-tree-and-how-do-i-view-it/">accessibility tree</a>, as it provides guidance and assistance to those who use screen readers and other assistive technology to understand the contents of the page.</p> </blockquote> <p>So no need to <code>aria-hidden</code> or <code>role="presentation"</code> or anything. But you can make it visually hidden through various means of CSS, like the following I got from <a href="https://webaim.org/techniques/css/invisiblecontent/#offscreen">WebAIM's recommendation</a>:</p> <pre><code class="language-css">.sr-only { position:absolute; left:-10000px; top:auto; width:1px; height:1px; overflow:hidden; }</code></pre> <blockquote> <p>The <code>.sr-only</code> CSS class ("sr-only" meaning "screen reader only", though the class name does not really matter) should then be referenced from within the tag of the element being hidden ... Sighted users will not see the hidden content at all—it will be hidden well to the left of the visible browser window. Because it is still part of the page content, screen readers will read it.</p> </blockquote> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/xscottxbrownx"><img src="https://avatars.githubusercontent.com/u/71395931?v=4" />xscottxbrownx</a> commented <strong> 9 months ago</strong> </div> <div class="markdown-body"> <p>@milofultz could you Friend request on Discord, to make this convo a little easier? I've got just a couple ideas to run by you - thinking about this for all the pages.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/milofultz"><img src="https://avatars.githubusercontent.com/u/65684361?v=4" />milofultz</a> commented <strong> 8 months ago</strong> </div> <div class="markdown-body"> <p>Hey @xscottxbrownx , I thought I friended you on Discord, but now I'm not so sure 🙃 . What is your username? You can shoot me a message too at <code>@milofultz</code></p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/xscottxbrownx"><img src="https://avatars.githubusercontent.com/u/71395931?v=4" />xscottxbrownx</a> commented <strong> 8 months ago</strong> </div> <div class="markdown-body"> <blockquote> <p>Hey @xscottxbrownx , I thought I friended you on Discord, but now I'm not so sure 🙃 . What is your username? You can shoot me a message too at <code>@milofultz</code></p> </blockquote> <p>Found you and sent message - username: veganedge</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/milofultz"><img src="https://avatars.githubusercontent.com/u/65684361?v=4" />milofultz</a> commented <strong> 8 months ago</strong> </div> <div class="markdown-body"> <p>Going through this again and noticing that some headings were downgraded to just <code>strong</code> tags, but they are definitely headings in that they "<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements#nesting">reflect the organization of the content</a>" (Secure Storage, etc.).</p> <img width="938" alt="Screen Shot 2023-11-12 at 10 03 34 AM" src="https://github.com/codeforpdx/PASS/assets/65684361/62de3543-b203-4fb4-a83c-62d5a740d8cb"> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>