你可能不需要 role="presentation"

For a brief moment in time, my main job was to assess the compliance of a selection of websites and document this in a report that was handed over to the customer. I carried out this assessment using the so-called BIK BITV test and, in test step 9.4.1.2 Name, Role, Value, I noticed time and again that role="presentation" was used in a way that was either technically questionable or even degraded accessibility.

有一段时间,我的主要工作是评估一组网站的合规性,并将此记录在报告中递交给客户。我使用所谓的 BIK BITV test 进行此评估,并且在测试步骤 9.4.1.2 Name, Role, Value 中,我一次又一次注意到 role="presentation" 的使用方式要么在技术上值得商榷,要么甚至降低了可访问性。

Because I have seen this pattern so often, I’m going to to use a couple of real-life examples to find out why this is the case. The examples have been edited and shortened to make them easier to understand.

因为我见过这种模式太多次了,我将使用几个真实生活中的例子来找出原因。这些例子已被编辑和缩短,以使其更容易理解。

I will use the code to assess what the intention for using role="presentation" might have been and what could have been done differently. In my experience, there’s only a few real use cases for this attribute value, which we will get to later in the article.

我将使用代码来评估使用 role="presentation" 的意图可能是什么,以及可以做些什么不同的事情。根据我的经验,这个属性值只有少数真正的用例,我们将在文章后面讨论。

What you might read about this attribute

你可能会读到的关于此属性的描述

We will use the specifications to take a closer look at what role="presentation" does, how it is used in the wild, and what it should actually be used for.

我们将使用规范来更仔细地查看role="presentation"的作用、在实际使用中的情况,以及它实际应该用于什么。

The official specs

官方规范

Whenever you see a blockquote following a code sample in this section, it is an excerpt from the specification.

每当你在这个部分看到代码示例后面的blockquote时,它就是来自规范的摘录。

If you take a look at the specification, you will immediately notice the prominent note right at the beginning (emphasis ours):

如果您查看 规范,您会立即注意到开头处突出的说明(强调为我们添加):

In ARIA 1.1, the working group introduced none as a synonym to the presentation role, due to author confusion surrounding the intended meaning of the word “presentation” or “presentational.” Many individuals erroneously consider role="presentation" to b...

开通本站会员,查看完整译文。

Главная - Вики-сайт
Copyright © 2011-2026 iteam. Current version is 2.153.0. UTC+08:00, 2026-02-15 00:33
浙ICP备14020137号-1 $Гость$