确保所有可感知的文本包含在 ARIA 地标中。

huangapple go评论76阅读模式
英文:

Ensure all perceivable text is included in an ARIA landmark

问题

我已经创建了一个HTML页面,当我进行可访问性测试时,我得到了一些ARIA标志的建议,如下所示:

确保所有可察觉的文本都包含在ARIA标志中。

基于这个建议,我已经为标题标签添加了一些标志,如下所示:

<div class="sign-up-title-container">
  <h1 class="sign-up-title" role="heading" aria-level="1" aria-label="Sign up now" style="color: #000000; background-color: #fcb913">
     Sign up now
  </h1>
</div>
<div class="sw-cta-container-v1">
  <p class="sw-cta-sub-text-v1" role="presentation" aria-label="Already a member?">
Already a member?
  <span>
    <a class="sw-cta-text-v1" role="button" aria-label="Log In" href="/en-us/login/?redir=/en-us/home/">Log In</a>
  </span>
  </p>
</div>

根据建议,我已经添加了role属性作为标题,并使用了aria-level="1"aria-label="Sign up now"

但在重新运行测试后,我仍然面临着相同的消息:

确保所有可察觉的文本都包含在ARIA标志中。

不确定我做错了什么。有人可以建议我哪里出错吗?

英文:

I have created a html page when i do the accessibility testing i got some ARIA-landmarks suggesstions like below

Ensure all perceivable text is included in an ARIA landmark.

Using that i have added some landmarks for the heading tags like below

&lt;div class=&quot;sign-up-title-container&quot;&gt;
  &lt;h1 class=&quot;sign-up-title&quot; role=&quot;heading&quot; aria-level=&quot;1&quot; aria-label=&quot;Sign up now&quot; style=&quot;color: #000000; background-color: #fcb913&quot;&gt;
     Sign up now
   &lt;/h1&gt;
&lt;/div&gt;
&lt;div class=&quot;sw-cta-container-v1&quot;&gt;
  &lt;p class=&quot;sw-cta-sub-text-v1&quot; role=&quot;presentation&quot; aria-label=&quot;Already a member?&quot;&gt;
Already a member?
  &lt;span&gt;
    &lt;a class=&quot;sw-cta-text-v1&quot; role=&quot;button&quot; aria-label=&quot;Log In&quot; href=&quot;/en-us/login/?redir=/en-us/home/&quot;&gt;Log In&lt;/a&gt;
  &lt;/span&gt;
  &lt;/p&gt;
&lt;/div&gt;

Based on the suggestions i have added the role as heading with aria-level="1" and aria-label="Sign up now"

But after running the test again i am facing the same message

Ensure all perceivable text is included in an ARIA landmark.

Not sure what i am doing wrong. Could anyone suggest me what is mistake i am doing.

答案1

得分: 2

示例代码不包括任何地标,因此消息将保留。添加的ARIA属性是有害的,会降低可访问性,您应该考虑全部删除它们。

地标是一个抽象角色,用于内容部分,它足够重要,以至于用户可能希望能够轻松导航到该部分,并在页面的动态生成摘要中包含它。地标允许辅助技术快速导航和查找内容。

来自MDN上的ARIA:地标角色,本答案已经添加了强调。

由于landmark是一个抽象角色,您需要为您的部分使用其中一个派生角色,如formregion

任何<form>已经是一个地标角色,应该具有有用的可访问名称。这似乎与手头的示例相关,其中存在两个表单(注册和登录)。

<form class="sign-up-title-container" aria-labelledby="sign-up-title">
  <h1 class="sign-up-title" id="sign-up-title" style="color: #000000; background-color: #fcb913">
     立即注册
   </h1>
</form>

这将提供一个已命名的地标,辅助技术的用户可以直接在页面地标列表中找到并导航到它。


关于建议的ARIA属性的问题。

使用ARIA规定了一些基本规则:

如果您可以使用具有所需语义和行为的本机HTML元素[HTML51]或属性,而无需重新使用元素并添加ARIA角色、状态或属性以使其可访问,那么请这样做。

除非确实必须,否则不要更改本机语义。

不要 <h1 role="heading" aria-level="1">
要 <h1>

明确定义了<h1>元素已经具有的角色和级别,这只是一个更冗长的版本,应该避免使用。下一部分也是一样的,因为元素的可访问名称默认是其文本内容:

不要 <h1 aria-label="立即注册">立即注册</h1>
要 <h1>立即注册</h1>
不要 <p role="presentation">
要 <p>

<p>元素具有paragraph的隐含角色。通过将其更改为presentation,将从此元素中去除了任何语义,这会使辅助技术的用户更难导航文档。

presentation角色及其同义词none会从公共可访问性树中删除元素的隐含ARIA语义。

根据ARIA标准,不允许命名呈现元素,因此必须删除aria-label

<a role="button" href="…

这会删除<a href>已经具有的link角色。它有助于用户理解与元素交互将引发某种形式的导航。

相反,应用了button角色

button角色用于在用户激活时触发响应的可点击元素。

如果只更改UI的一部分的可见性,这样做是有道理的。在Web上,"按钮或链接"已经得到了很好的覆盖。

英文:

The example code does not include any landmark, so the message will persist. The added ARIA attributes are harmful and deteriorating accessibility, you should probably remove them all.

> A landmark is an abstract role for a section of content that is important enough that users will likely want to be able to navigate to the section easily and have it included in a dynamically generated summary of the page. Landmarks allow assistive technologies to navigate and to find content quickly.

From ARIA: landmark role on MDN, emphasis was added for this answer.

Since landmark is an abstract role, you need to use one of the derived roles for your section, like form or region.

Any &lt;form&gt; is already a landmark role, and should have a helpful accessible name. This seems relevant to the example at hand, were two forms (sign-up and log-in) exist.

&lt;form class=&quot;sign-up-title-container&quot; aria-labelledby=&quot;sign-up-title&quot;&gt;
  &lt;h1 class=&quot;sign-up-title&quot; id=&quot;sign-up-title&quot; style=&quot;color: #000000; background-color: #fcb913&quot;&gt;
     Sign up now
   &lt;/h1&gt;
&lt;/form&gt;

This will provide a named landmark, that users of assistive technology can directly find in a list of page landmarks and navigate to it.


For the issues with the suggested ARIA attributes.

Using ARIA states some foundational rules:

> If you can use a native HTML element [HTML51] or attribute with the semantics and behavior you require already built in, instead of re-purposing an element and adding an ARIA role, state or property to make it accessible, then do so.

> Do not change native semantics, unless you really have to.

Don’t &lt;h1 role=&quot;heading&quot; aria-level=&quot;1&quot;&gt;
Do &lt;h1&gt;

Is explicitly defining the role and level again, that the &lt;h1&gt; element already has. It’s only a more verbose version and should be avoided. The same goes for the next part, which also achieves nothing different, as the accessible name of an element is by default it’s text contents:

Don’t &lt;h1 aria-label=&quot;Sign up now&quot;&gt;Sign up now&lt;/h1&gt;
Do &lt;h1&gt;Sign up now&lt;/h1&gt;
Don’t &lt;p role=&quot;presentation&quot;&gt;
Do &lt;p&gt;

A &lt;p&gt; element has an implicit role of paragraph. By changing it to presentation, any semantics are taken away from this element, which makes navigating the document harder for users of assistive technology.

> The presentation role and its synonym none remove an element's implicit ARIA semantics from being exposed to the accessibility tree.

Naming presentational elements is prohibited as per ARIA standard, so aria-label must be removed.

&lt;a role=&quot;button&quot; href=&quot;…

This is taking away the link role that &lt;a href&gt; already has. It helps users understand that interacting with the element will cause some form of navigation.

Instead, the button role is applied:

> The button role is for clickable elements that trigger a response when activated by the user.

It can make sense to do so, if only visibility of a part of the UI is changed. “button or link” is covered to a large extend on the web.

答案2

得分: 2

@andy在他的回答中提供了一些有用的信息,尤其是关于在代码中添加额外的ARIA以尝试“修复”地标问题的部分。

你没有说你用什么工具来扫描页面以检查可访问性,但无论如何,建议所有内容都包含在地标中的工具纯粹是一些建议,而不是WCAG或可访问性要求。

当然,鼓励您将所有内容放在地标中,但您不必这样做。如果您确实希望使用地标,请在添加role之前尝试使用本机HTML元素。因此,您的页面结构可能如下所示:

<header>
  <!-- 公司徽标,主要顶部导航元素,等等 -->
  <nav>
    <!-- 主要顶部导航 -->
  </nav>
</header>

<main>
  <!-- 页面正文部分 -->
</main>

<footer>
  <!-- 典型的页脚链接 -->
</footer>

上面示例中的所有HTML元素都具有默认的地标角色:

  • &lt;header>(如果在页面级别上,它是banner地标)
  • &lt;nav>(具有navigation角色)
  • &lt;main>(具有main角色)
  • &lt;footer>(如果在页面级别上,它是contentinfo角色)
英文:

@andy has some good info in his answer, especially regarding all the extra ARIA that was added to the code to try to "fix" the landmark issue.

You didn't say what tool you used to scan the page to check the accessibility, but in any event, tools that recommend that all content be contained in a landmark is purely a suggestion and not a WCAG or accessibility requirement.

You're certainly encouraged to have everything in a landmark but you don't have to. If you do want landmarks, try to use native HTML elements first before resorting to adding a role. So your page structure might be something like this:

&lt;header&gt;
  &lt;!-- company logo, main top navigation elements, etc --&gt;
  &lt;nav&gt;
    &lt;!-- main top navigation --&gt;
  &lt;/nav&gt;
&lt;/header&gt;

&lt;main&gt;
  &lt;!-- body of page --&gt;
&lt;/main&gt;

&lt;footer&gt;
  &lt;!-- typical footer links --&gt;
&lt;/footer&gt;

All of the HTML elements in the example above have default landmark roles:

huangapple
  • 本文由 发表于 2023年7月10日 18:18:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76652787.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定