UDOIT icon indicating copy to clipboard operation
UDOIT copied to clipboard

pNotUsedAsHeader triggered even if role="heading" is used

Open robfentress opened this issue 9 years ago • 3 comments

The pNotUsedAsHeader rule is triggered, even if role="heading" has been used to indicate that a styled <p> tag is to serve as a heading. For example, this throws a warning:

<p role="heading" aria-level="1"><strong><span style="font-size: 24pt;">I'm a level 1 heading</span></strong></p>
<div role="heading" aria-level="2"><strong><span style="font-size: 18pt;">I'm a level 2 heading</span></strong></div>
<p>I suspect this will trigger a warning about adding headings, but we'll see.</p>
<p><img src="/courses/45/files/5563/preview" alt="The W3C" width="72" height="48" data-api-endpoint="https://vt.test.instructure.com/api/v1/courses/45/files/5563" data-api-returntype="File" /></p>
<p role="heading" aria-level="2"><strong><span style="font-size: 18pt;">I'm another level 2 heading</span></strong></p>
<p>But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure? On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee.</p>
<p>But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it?</p>
<p role="heading" aria-level="2"><strong><span style="font-size: 18pt;">I'm also a level 2 heading</span></strong></p>
<p>But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure? On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee.</p>
<p><span>No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure.</span></p>

screen shot 2016-02-24 at 4 08 03 pm

robfentress avatar Feb 24 '16 21:02 robfentress

https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/heading_role

The best way to use this role is to not use it at all, and instead use the native heading tags <h1> through <h6>

AlanFCMV avatar Dec 03 '21 15:12 AlanFCMV

Indeed, it is true that ARIA should generally be avoided where possible. However, using role="heading" to indicate something is a heading is a technically valid solution and I don't think this should be considered an accessibility violation when used, especially given what appears to be be universal support for this role by screen readers. I think to label it as a violation is misleading. There may be edge cases where it is appropriate to use (else why even have it in ARIA?).

robfentress avatar Dec 03 '21 16:12 robfentress

Let's have this conversation in #99

bagofarms avatar Dec 03 '21 16:12 bagofarms