菜单列表项被视为按访问性工具的按钮,但不是

发布于 2025-02-03 00:43:20 字数 1234 浏览 2 评论 0原文

我用一种可访问性工具测试了我的网站。结果,它报告了我的网站菜单不合规,因为:

用作按钮但使用其他标签(例如跨度,div,a或其他)构建的元素应包括一个等于“按钮”的“角色”属性。

实际上,这是一个通用的< li>标签,没有单击操作或其他任何。

  <div class="ch-wp-menu-item-dropdown-wrapper">
    <ul class="ch-wp-menu-item-dropdown">
      <li class="ch-wp-menu-item-dropdown-content">

        {% for subItem in item.values %}
        <div class="ch-wp-menu-item-subitem">
          <ul>
            <li class="ch-wp-menu-item-subitem-title" tabindex="0"> //the element that accessibility tool refers to
              {{subItem.name}}
            </li>
            {% for value in subItem.values %}
            <li>
              <a href="{{value.value}}"
                tabindex="0"
                aria-label="{{value.name}}">
                <div class="ch-wp-menu-item-subitem-record">{{value.name}}</div>
              </a>
            </li>
            {% endfor %}
          </ul>
        </div>
        {% endfor %}

      </li>
      <div class="ch-wp-menu-item-dropdown-backdrop"></div>
    </ul>
  </div>

您能否建议造成此错误的原因是什么?

I tested my website with one of the accessibility tools. As the result it reported that my website menu is not compliant because:

Elements that behave as buttons but are built using other tags such as span, div, a or others, should include a "role" attribute that equals to "button".

In fact, this is a general <li> tag that has no click actions or whatever.

  <div class="ch-wp-menu-item-dropdown-wrapper">
    <ul class="ch-wp-menu-item-dropdown">
      <li class="ch-wp-menu-item-dropdown-content">

        {% for subItem in item.values %}
        <div class="ch-wp-menu-item-subitem">
          <ul>
            <li class="ch-wp-menu-item-subitem-title" tabindex="0"> //the element that accessibility tool refers to
              {{subItem.name}}
            </li>
            {% for value in subItem.values %}
            <li>
              <a href="{{value.value}}"
                tabindex="0"
                aria-label="{{value.name}}">
                <div class="ch-wp-menu-item-subitem-record">{{value.name}}</div>
              </a>
            </li>
            {% endfor %}
          </ul>
        </div>
        {% endfor %}

      </li>
      <div class="ch-wp-menu-item-dropdown-backdrop"></div>
    </ul>
  </div>

Could you advise what might be the reason for this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的旅程 2025-02-10 00:43:20

尝试更改标签,

<a role="button" href="{{value.value}}" tabindex="0" aria-label="{{value.name}}">
    <div class="ch-wp-menu-item-subitem-record">{{value.name}}</div>
</a>

以指出现在设置了角色属性。

Try changing your a tag to

<a role="button" href="{{value.value}}" tabindex="0" aria-label="{{value.name}}">
    <div class="ch-wp-menu-item-subitem-record">{{value.name}}</div>
</a>

Note that the role attribute has now been set.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文