简体   繁体   English

Aria-live 和显示/隐藏表格

[英]Aria-live and showing/hiding a form

I have an Angular 14 app where I display some content.我有一个 Angular 14 应用程序,我在其中显示一些内容。 There is a button to put this into "edit mode" wherein I hide the content and show a form.有一个按钮可以将其置于“编辑模式”,在其中我隐藏内容并显示表单。 When the user edits the form and clicks "done", the form is hidden and the updated content shows.当用户编辑表单并单击“完成”时,表单被隐藏并显示更新的内容。

This works fine, but I am trying to make this accessible.这很好用,但我正在努力使其易于访问。 I added an aria-live to the part with the form and when it is shown the entire form is read out loud using VoiceOver on Mac, but you don't know it's a form.我在表格的部分添加了一个aria-live ,当它显示时,整个表格会在 Mac 上使用 VoiceOver 大声读出,但你不知道它是一个表格。 You can tab to the fields and edit the form, though, and then click Done and the form goes away.不过,您可以选择字段并编辑表单,然后单击“完成”,表单就会消失。

However, how do I let unsighted users know that (1) a form has appeared and then (2) the form have disappeared and the regular content has re-appeared?但是,我如何让没有视力的用户知道 (1) 表单出现了,然后 (2) 表单消失了,而常规内容又重新出现了?

I have made a stripped down Stackblitz to illustrate.我做了一个精简的Stackblitz来说明。

It's basically this HTML:基本上就是这个 HTML:

<div class="container">
  <div class="row">
    <div class="col">
      <div *ngIf="!showForm" aria-live="polite">
        <h1>
          Hello {{ myForm.controls.fname.value }}
          {{ myForm.controls.lname.value }}
        </h1>

        <button class="btn btn-secondary" type="button" (click)="onEditForm()">
          Edit Greeting
        </button>
      </div>

      <form [formGroup]="myForm" *ngIf="showForm" aria-live="polite">
        <h3 class="sr-only">Edit Greeting Form</h3>

        <div class="form-group mb-4">
          <label for="fname">First Name</label>
          <input
            type="text"
            id="fname"
            formControlName="fname"
            class="form-control"
          />
        </div>

        <div class="form-group mb-4">
          <label for="lname">Last Name</label>
          <input
            type="text"
            id="lname"
            formControlName="lname"
            class="form-control"
          />
        </div>

        <button type="button" class="btn btn-primary" (click)="onDoneForm()">
          DONE
        </button>
      </form>
    </div>
  </div>
</div>

ARIA live regions aren't well suited for elements containing a lot of text or other things. ARIA 活动区域不太适合包含大量文本或其他内容的元素。 The screen reader will read them all at once, and, for long things, it's rarely the best thing to do because the user can't interrupt or pause the read, or if he/she does it, the rest is kind of lost.屏幕阅读器将一次性阅读所有内容,而且对于长时间的阅读,这很少是最好的做法,因为用户无法中断或暂停阅读,或者如果他/她这样做了,rest 有点迷路了。

A much better thing to do for forms is to put the focus on the first input field.对于 forms 来说,更好的做法是将焦点放在第一个输入字段上。 The first label will be read as well as the field type, and so the user will know that he/she has to enter some information, and then will press tab to go to the next field, and so on.将读取第一个 label 以及字段类型,因此用户将知道他/她必须输入一些信息,然后将按 Tab 到 go 到下一个字段,依此类推。

Additionally to that, you can use ARIA live, but not on the form or content shown itself.除此之外,您可以实时使用 ARIA,但不能在显示的表单或内容上使用。 The best use of ARIA live is for displaying short strings saying "The form is shown", "Content is loading", "Your request has been submitted", "There are 12 search results", etc. ARIA live 的最佳用途是显示短字符串,例如“显示表单”、“正在加载内容”、“您的请求已提交”、“有 12 个搜索结果”等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM