画外音和屏幕读取器:如何编码无线电按钮

发布于 2025-01-21 18:17:21 字数 3211 浏览 5 评论 0原文

我在iPad上使用Voiceover/Chrome来测试我正在开发的页面上的可访问性是否有效。我将蓝牙键盘连接到iPad,然后单击“选项卡键”以浏览页面上的元素。该页面上使用的以下代码可与VoiceOver一起使用:

<div>
    <div class="radio"> 
        <label tabindex="0">
            <input type="radio"  name="abc" value="0" aria-labelledby="q1015678-2430294-button"> <span id="q1015678-2430294-button">Good</span>
        </label>
    </div>
    <div class="radio">
        <label tabindex="0">
            <input type="radio"  name="abc" value="1" aria-labelledby="q1015678-2430295-button"> <span id="q1015678-2430295-button">Bad</span>
        </label>
    </div>
</div>

但是,当我在Windows上使用屏幕读取器/Chrome时,上面的代码发音为“良好”,然后说“好,无线电按钮”。在两个选择中,对于另一个“不良”单选按钮也是如此。

编码无线电和屏幕阅读器工作的无线电按钮的正确方法是什么?

更新

这是测试中使用的HTML。配音未能发现在V2和V3中编码的按钮。它可以正确识别和发音“此开始”,v1中的按钮和“这是终点”。

我能够用左/滑动手势浏览所有按钮。问题是使用键盘上的“选项卡键”将选项卡通过按钮。 iPad上的iOS为15.4.1。

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
<body>

  <form>

    <div tabindex="0" role="text">this is the beginning</div>

    <div>-----------v1------------</div>

    <div>
      <div class="radio">
        <label tabindex="0">
          <input type="radio" name="abc" value="0" aria-labelledby="q1015678-2430294-button"> <span
            id="q1015678-2430294-button">Good</span>
        </label>
      </div>
      <div class="radio">
        <label tabindex="0">
          <input type="radio" name="abc" value="1" aria-labelledby="q1015678-2430295-button"> <span
            id="q1015678-2430295-button">Bad</span>
        </label>
      </div>
    </div>

    <div>----------v2-------------</div>

    <div>
      <div class="radio">
        <label for="q1015678-2430294-button2">
          <input type="radio" name="ddd" value="0" id="q1015678-2430294-button2"> <span>Good 2</span>
        </label>
      </div>
      <div class="radio">
        <label for="q1015678-2430295-button2">
          <input type="radio" name="ddd" value="1" id="q1015678-2430295-button2"> <span>Bad 2</span>
        </label>
      </div>
    </div>

    <div>-----------v3------------</div>

    <div>
      <label for="xyz1">radio button 1</label>
      <input type="radio" id="xyz1" />
    </div>

    <div>
      <label for="xyz2">radio button 2</label>
      <input type="radio" id="xyz2" />
    </div>

    <div>-----------------------</div>

    <div tabindex="0" role="text">this is the end</div>
    
  </form>

</body>
</html>

如果我将以下文本框放在表单中,则配音可以通过页面上的元素正确发音。

<textarea name="ta">This is textarea</textarea>

更新3

在我对V1的测试(原始代码)中,Spacebar能够在Safari和Chrome中激活我iPad上的单选按钮。

I use VoiceOver/Chrome on a iPad to test whether accessibility works on a page I am developing. I connect a Bluetooth keyboard to the iPad and click on the Tab key to go through elements on the page. The following code used on the page works with VoiceOver:

<div>
    <div class="radio"> 
        <label tabindex="0">
            <input type="radio"  name="abc" value="0" aria-labelledby="q1015678-2430294-button"> <span id="q1015678-2430294-button">Good</span>
        </label>
    </div>
    <div class="radio">
        <label tabindex="0">
            <input type="radio"  name="abc" value="1" aria-labelledby="q1015678-2430295-button"> <span id="q1015678-2430295-button">Bad</span>
        </label>
    </div>
</div>

However, when I use Screen Reader/Chrome on Windows, the above code pronounces "Good Good" before saying "Good, radio button". The same goes for the other "Bad" radio button when tabbing through the two choices.

What is the proper way of coding radio buttons that works with both VoiceOver and Screen Reader work?

Update

This is the HTML used in the test. VoiceOver fails to discover buttons coded in v2 and v3. It can identify and pronounce correctly "This the beginning", buttons in v1, and "This is the end".

I was able to tab through all buttons with the left/swipe gestures. The problem is to use the Tab key on a keyboard to tab through the buttons. The ios on the iPad is 15.4.1.

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
<body>

  <form>

    <div tabindex="0" role="text">this is the beginning</div>

    <div>-----------v1------------</div>

    <div>
      <div class="radio">
        <label tabindex="0">
          <input type="radio" name="abc" value="0" aria-labelledby="q1015678-2430294-button"> <span
            id="q1015678-2430294-button">Good</span>
        </label>
      </div>
      <div class="radio">
        <label tabindex="0">
          <input type="radio" name="abc" value="1" aria-labelledby="q1015678-2430295-button"> <span
            id="q1015678-2430295-button">Bad</span>
        </label>
      </div>
    </div>

    <div>----------v2-------------</div>

    <div>
      <div class="radio">
        <label for="q1015678-2430294-button2">
          <input type="radio" name="ddd" value="0" id="q1015678-2430294-button2"> <span>Good 2</span>
        </label>
      </div>
      <div class="radio">
        <label for="q1015678-2430295-button2">
          <input type="radio" name="ddd" value="1" id="q1015678-2430295-button2"> <span>Bad 2</span>
        </label>
      </div>
    </div>

    <div>-----------v3------------</div>

    <div>
      <label for="xyz1">radio button 1</label>
      <input type="radio" id="xyz1" />
    </div>

    <div>
      <label for="xyz2">radio button 2</label>
      <input type="radio" id="xyz2" />
    </div>

    <div>-----------------------</div>

    <div tabindex="0" role="text">this is the end</div>
    
  </form>

</body>
</html>

If I put the following textbox in the form, the VoiceOver is able to pronounce it correctly with the tab key tabbing through the elements on the page.

<textarea name="ta">This is textarea</textarea>

Update 3

In my tests of v1 (the original code), the spacebar is able to activate a radio button on my ipad in both Safari and Chrome.

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

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

发布评论

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

评论(2

末骤雨初歇 2025-01-28 18:17:21

乍一看,您的代码中有两件事看起来很奇怪:

  • 标签具有tabindex = 0
  • aria-labelledby中引用的ID

在第一个点的标签内,标签上的tabindex = 0使该标签可集中。但是,标签不应该集中。只有单选按钮应该是,默认情况下是不指定Tabindex的。
这就是为什么您首先访问标签的原因,并且由于您首先访问标签,因此您无法对其做任何事情。

解决方案:从标签中删除Tabindex = 0的

第二点,它可能起作用,但仍然是一个奇怪的结构。
当您需要引用与正常标签不同的标签元件时,必须使用ARIA标签。

  • 如果&lt; label&gt;参考&lt; input&gt; element in 属性>属性,则您不需要额外的Aria-labelledby。
  • 当文本在相同的&lt; label&gt;中作为&lt; input&gt;时,您也不需要Aria-labelled。
  • 如果您只需要封闭&lt; label&gt;是实际可访问的标签,则最好切换到另一个更常规的构造,其中&lt; input&gt; isn 't在&lt; label&gt;中。然后,使用Aria-labelledby时的混乱将减少,如果您希望仍然具有与&lt; label&gt;中的标签不同的标签。

我希望这足够清楚。我的建议:切换到这样的简单结构:

<div>
<label for="xyz">Label of the radio button</label>
<span>Some additional text not present in accessible label, if you want</span>
<input type="radio" id="xyz" />
<span>Some additional text not present in accessible label, if you want</span>
</div>

At a first glance, two things look strange in your code:

  • The label has tabindex=0
  • The id referenced in aria-labelledby is inside the label

For the first point, the tabindex=0 on the label make that label focusable. However, the label isn't supposed to be focusable. Only the radio button should be, and it is by default without specifying tabindex.
This is precisely why you first reach the label by itself, and since you first reach the label by itself, you can't do anything with it.

Solution: remove tabindex=0 from the label

For the second point, it might work, but it's still quite an odd construction.
The aria-labelledby has to be used when you need to reference a labelling element different than the normal label.

  • If the <label> references the <input> element in its for attribute, you don't need an additional aria-labelledby.
  • When the text is inside the same <label> as the <input>, you don't need aria-labelledby either.
  • If you want only one part of the enclosing <label> be the actual accessible label, you'd better switch to another more conventional construction where the <input> isn't inside the <label>. Then there will be less confusion when using aria-labelledby, if you want still to have a different accessible label than what's inside the <label>.

I hope it's clear enough. My advice: switch to a simpler construction like this:

<div>
<label for="xyz">Label of the radio button</label>
<span>Some additional text not present in accessible label, if you want</span>
<input type="radio" id="xyz" />
<span>Some additional text not present in accessible label, if you want</span>
</div>
oО清风挽发oО 2025-01-28 18:17:21

此答案,激活“完整的键盘访问“选项使无线电按钮可随着标签的规定触及。
我的第一个答案提供有关代码的建议保持有效。

好消息是,我们观察到的不是错误。苹果使它像这样有意。

坏消息是,配音和完整的键盘访问效果不佳。

例如,当打开完整的键盘访问时,我无法再启用/禁用快速导航,并且使用转子遇到了很大的麻烦。其他一些重要的配音功能似乎也受到影响。
作为盲人和配音用户,我真的无法启用完整的键盘访问。

从那里开始,可以推断出,作为屏幕读取器用户,您不应该使用选项卡进行导航。您应该专门使用屏幕读取器特定功能。
在这里,vo手势。

它还表明,实际上,您的测试是错误的:

  • 由于VO用户不应该使用选项卡进行导航,因此,如果通常可以通过vo手势到达并操作所有内容,那么您对屏幕阅读器用户的用户很好。
  • 检查所有交互式元素都可以通过选项卡到达所有交互式元素,实际上是另一个测试,对于键盘用户来说,这些用户在触摸接口方面遇到问题,但没有视力。

如果在PC上您可以同时测试这两种情况,则看起来它不在iPhone和iPad上,因为Apple似乎已决定将两种用户完全分开。知道为什么,以及最多的Macintosh会很有趣。

As explained in this answer, activating the "full keyboard access" option make the radio buttons reachable with tab as they normally should.
My first answer giving advice on the code stays valid.

The good news is that what we have observed isn't a bug. Apple made it working like this intentionally.

The bad news is that VoiceOver and full keyboard access aren't playing well together.

For example, when full keyboard access is turned on, I can no longer enable/disable quick navigation, and I have big troubles using the rotor. Several other important VoiceOver functions seem to be affected, too.
As a blind and VoiceOver user, I really can't keep full keyboard access enabled.

From there, one can deduce that, as a screen reader users, you aren't supposed to use tab to navigate. You should exclusively be using screen reader specific functions.
Here, VO gestures.

It also shows that, in fact, your test is incorrectly designed:

  • Since a VO user isn't supposed to use tab to navigate, if everything can normally be reached and operated with VO gestures, you are fine for screen reader users.
  • Checking that all interactive elements are reachable with tab is in fact another test, for keyboard only users, who have problems with touch interfaces but none with vision.

If, on a PC, you can test both at the same time, it looks like it's not on iPhone and iPad, because Apple seem to have decided to completely separate the two kinds of users. It would be interesting to know why, and where the most goes the macintosh.

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