Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkbox can end up with multiple aria-describedby attributes when used without a fieldset but with a hint #1248

Closed
36degrees opened this issue Mar 13, 2019 · 1 comment · Fixed by #1265
Assignees
Labels
accessibility 🐛 bug Something isn't working the way it should (including incorrect wording in documentation) ⚠️ high priority Used by the team when triaging 🕔 hours A well understood issue which we expect to take less than a day to resolve.

Comments

@36degrees
Copy link
Contributor

36degrees commented Mar 13, 2019

The checkbox component has some logic to move the association with the error message (aria-describedby) to the input if there is no fieldset (e.g. for a single input).

It also has logic to associate the hint for the individual checkbox if a hint is provided.

We don't handle the (admittedly fairly unlikely) case where both of these things are true, so the checkbox will end up with two aria-describedby attributes (aria-describedby="id-of-error-message" aria-describedby="id-of-hint")

{%- if (not hasFieldset) and ((describedBy | length) > 0) %} aria-describedby="{{ describedBy }}"{% endif -%}
{%- if item.conditional %} data-aria-controls="{{ conditionalId }}"{% endif -%}
{%- if hasHint %} aria-describedby="{{ itemHintId }}"{% endif -%}

You can reproduce this with the following macro call:

{% from "checkboxes/macro.njk" import govukCheckboxes %}

{{ govukCheckboxes({
  "name": "t-and-c",
  "errorMessage": {
    "text": "Please accept the terms and conditions"
  },
  "items": [
    {
      "value": "yes",
      "text": "I agree to the terms and conditions",
      "hint": {
        "text": "Go on, you know you want to!"
      }
    }
  ]
}) }}

which produces this HTML:

<div class="govuk-form-group govuk-form-group--error">
  <span id="t-and-c-error" class="govuk-error-message">
    Please accept the terms and conditions
  </span>
  <div class="govuk-checkboxes">
    <div class="govuk-checkboxes__item">
      <input class="govuk-checkboxes__input" id="t-and-c-1" name="t-and-c" type="checkbox" value="yes" aria-describedby="t-and-c-error" aria-describedby="t-and-c-1-item-hint">
      <label class="govuk-label govuk-checkboxes__label" for="t-and-c-1">
        I agree to the terms and conditions
      </label>      <span id="t-and-c-1-item-hint" class="govuk-hint govuk-checkboxes__hint">
        Go on, you know you want to!
      </span>    </div>
  </div>
</div>

instead of:

<div class="govuk-form-group govuk-form-group--error">
  <span id="t-and-c-error" class="govuk-error-message">
    Please accept the terms and conditions
  </span>
  <div class="govuk-checkboxes">
    <div class="govuk-checkboxes__item">
      <input class="govuk-checkboxes__input" id="t-and-c-1" name="t-and-c" type="checkbox" value="yes" aria-describedby="t-and-c-error t-and-c-1-item-hint">
      <label class="govuk-label govuk-checkboxes__label" for="t-and-c-1">
        I agree to the terms and conditions
      </label>      <span id="t-and-c-1-item-hint" class="govuk-hint govuk-checkboxes__hint">
        Go on, you know you want to!
      </span>    </div>
  </div>
</div>
@36degrees 36degrees added awaiting triage Needs triaging by team accessibility 🐛 bug Something isn't working the way it should (including incorrect wording in documentation) labels Mar 13, 2019
@colinrotherham
Copy link
Contributor

@36degrees I might end up looking at this as part of #1079

I need a way for nested fieldset radio buttons to be described by the hint shown on a parent fieldset.

@kellylee-gds kellylee-gds added 🕔 hours A well understood issue which we expect to take less than a day to resolve. ⚠️ high priority Used by the team when triaging and removed awaiting triage Needs triaging by team labels Mar 20, 2019
colinrotherham added a commit to colinrotherham/govuk-frontend that referenced this issue Mar 30, 2019
colinrotherham added a commit to colinrotherham/govuk-frontend that referenced this issue Apr 1, 2019
colinrotherham added a commit to colinrotherham/govuk-frontend that referenced this issue Apr 1, 2019
colinrotherham added a commit to colinrotherham/govuk-frontend that referenced this issue Apr 1, 2019
colinrotherham added a commit to colinrotherham/govuk-frontend that referenced this issue Apr 1, 2019
colinrotherham added a commit to colinrotherham/govuk-frontend that referenced this issue Apr 1, 2019
colinrotherham added a commit to colinrotherham/govuk-frontend that referenced this issue Apr 1, 2019
colinrotherham added a commit to colinrotherham/govuk-frontend that referenced this issue Apr 1, 2019
colinrotherham added a commit to colinrotherham/govuk-frontend that referenced this issue Apr 2, 2019
@aliuk2012 aliuk2012 self-assigned this Apr 3, 2019
colinrotherham added a commit to colinrotherham/govuk-frontend that referenced this issue Apr 5, 2019
colinrotherham added a commit to colinrotherham/govuk-frontend that referenced this issue Apr 5, 2019
colinrotherham added a commit to colinrotherham/govuk-frontend that referenced this issue Apr 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility 🐛 bug Something isn't working the way it should (including incorrect wording in documentation) ⚠️ high priority Used by the team when triaging 🕔 hours A well understood issue which we expect to take less than a day to resolve.
Projects
Development

Successfully merging a pull request may close this issue.

4 participants