ugent-library / biblio-backoffice

Apache License 2.0
5 stars 0 forks source link

Fix accessibility for field help texts #1650

Open verheyenkoen opened 4 days ago

verheyenkoen commented 4 days ago

Enhancement

In some places we have some help text below a field. Users using screen readers are missing this context since they will already have filled out the field before they notice the help text. This can be fixed by applying aria labels.

Either we add an id attribute to the help text element and reference that using the ~aria-describedby~ aria-details attribute on the form field element (preferred solution). Or we duplicate the help text in the aria-description attribute on the form field, but then we'd also need to add the aria-hidden="true" attribute to the help text so this information is not duplicated for them.

Here's an exhaustive list of fields to address:

Screenshots

image

HTML currently generated for this field:

<div class="mb-6 row">
  <label class="col-lg-3 col-form-label mt-2" for="type"
    >Publication type</label
  >
  <div class="col-lg-3">
    <select
      class="form-select form-control"
      name="type"
      id="type"
      hx-get="/publication/01J1VXWR3D7DCJ1F544DCDJ9H1/type/confirm"
      hx-headers='{"If-Match": "01J1W9HBZ274660ZAJ02WMHTPR"}'
      hx-target="#modals"
    >
      <option value="journal_article">Journal article</option>
      <option value="book">Book</option>
      <option value="book_chapter">Book chapter</option>
      <option value="book_editor">Book editor</option>
      <option value="issue_editor">Issue editor</option>
      <option value="conference">Conference</option>
      <option value="dissertation">Dissertation</option>
      <option value="miscellaneous" selected="">Miscellaneous</option></select
    ><small class="form-text text-muted"
      >Changing the publication type might result in data loss</small
    >
  </div>
</div>

Additional context

https://getbootstrap.com/docs/5.0/forms/overview/#form-text

Automatic testing scenario

Ideally this is tested generically for forms. We'd need to query for .form-text instances and see if they are linked correctly to the previous field, either via ~aria-describedby~ aria-details or duplicated in aria-description but then the .form-text element should also have the aria-hidden="true" attribute.

mietcls commented 4 days ago

Tasty stuff!

Either we add an id attribute to the help text element and reference that using the aria-describedby attribute on the form field element (preferred solution). Or we duplicate the help text in the aria-description attribute on the form field, but then we'd also need to add the aria-hidden="true" attribute to the help text so this information is not duplicated for them.

I'd go for the preferred solution so we don't have redundant code nor extra maintenance (duplicate text is doomed to be forgotten).

verheyenkoen commented 4 days ago

I'd go for the preferred solution so we don't have redundant code nor extra maintenance (duplicate text is doomed to be forgotten).

I just added the alternative in case the preferred solution is not "feasible" somehow. In case it's not, it should be a translated text anyway (I'll fix it if not), so it's still a one-place-edit.