我创建了一个隐藏/显示的分步组件,如果您单击步骤编号,它会显示内容。

它可以按预期工作,但是我在确保其可访问性方面遇到困难。


我似乎无法在1-4个链接上使用键盘进行切换,即使它们是<a>标记。


<div class="progress-steps">
<a class="showSingle" target="1"></a>
<a class="showSingle" target="2"></a>
<a class="showSingle" target="3"></a>
<a class="showSingle" target="4"></a>
</div>



我还想确保用户也可以通过键盘激活隐藏的内容。


<section id="progress-content" class="hide">
<div id="div1" class="targetDiv"><h3>Initiation</h3>
  <p><strong>Fill out the </strong><a class="bold-link" href="https://app.smartsheet.com/b/form?EQBCT=b6923f4b9dc347f384936e342e5d2b58" target="_blank" rel="noopener">Project Request Form</a>: Each request goes through a review process to determine if the project is ready to be worked on.</p>
  </div>
<div id="div2" class="targetDiv"><h3>Planning</h3>
  <p><strong>Kickoff</strong>: After approval, we will schedule a meeting between all involved parties to discuss the scope and direction of the project.</p>
  </div>
<div id="div3" class="targetDiv"><h3>Execution</h3>
  <p><strong>We get to work!</strong> The plan will be carried out — involving all key stakeholders. The final product will be tested and implemented.</p>
  </div>
<div id="div4" class="targetDiv"><h3>Assessment</h3>
  <p><strong>Metrics for Success</strong>: After completion of the project, we will obtain sign-off of deliverables and revisit in 6-12 months to ensure stakeholders needs are met.</p>
  </div>
</section>


我试过玩:focus并将role="tab" aria-selected="true"插入<a>标记中。

这是我的密码笔:https://codepen.io/ckatz/pen/gJmgbq

我想确保使用键盘的任何人都可以有效使用此组件。

最佳答案

通过将tabindex="0"添加到每个链接中,我可以进行浏览。在站点中进行制表时,这包括正常流程中的选项卡链接。

我还读到您实际上不应该对所有导航链接使用aria-selected="true",而应该仅对当前选择的链接使用。在此处了解更多信息:stefanjudis.com/blog/aria-selected-and-when-to-use-it

因此,您的步骤选择器将如下所示:

<div class="progress-steps">
<a class="showSingle" target="1" role="tab" tabindex="0" aria-controls="nils-tab"></a>
<a class="showSingle" target="2" role="tab" tabindex="0" aria-controls="nils-tab"></a>
<a class="showSingle" target="3" role="tab" tabindex="0" aria-controls="nils-tab"></a>
<a class="showSingle" target="4" role="tab" tabindex="0" aria-controls="nils-tab"></a>
</div>


尽管我无法通过空格或Enter选择聚焦的元素。我将不得不做一些更多的研究来弄清楚这是怎么回事!

07-24 09:44
查看更多