Skip to content

Hints and errors are not semantically associated with fieldsets #214

@edwardhorsford

Description

@edwardhorsford

I'm expecting that this library produce output markup that mirrors the design system reference markup.

It looks like hints and error messages are not associated correctly with fieldsets - and thus all items that use fieldset like radios and checkboxes. This is likely an accessibility issue - both that it's not following the reference implementation that's been tested hundreds of times, but also that errors aren't associated at all - and a screen reader user might not get it.

For a set of radios like this:
Screenshot 2024-05-01 at 12 49 15

The reference design system markup is:

<div class="nhsuk-form-group nhsuk-form-group--error">

  <fieldset class="nhsuk-fieldset" aria-describedby="example-error-hint example-error-error">
  <legend class="nhsuk-fieldset__legend">
    Have you changed your name?
  </legend>

  <div class="nhsuk-hint" id="example-error-hint">
    This includes changing your last name or spelling your name differently.
  </div>

  <span class="nhsuk-error-message" id="example-error-error">
    <span class="nhsuk-u-visually-hidden">Error:</span> Select yes if you have changed your name
  </span>

  <div class="nhsuk-radios">
    
    <div class="nhsuk-radios__item">
      <input class="nhsuk-radios__input" id="example-error-1" name="example-error" type="radio" value="yes">
      <label class="nhsuk-label nhsuk-radios__label" for="example-error-1">
        Yes
      </label>
    </div>
    
    
    <div class="nhsuk-radios__item">
      <input class="nhsuk-radios__input" id="example-error-2" name="example-error" type="radio" value="no">
      <label class="nhsuk-label nhsuk-radios__label" for="example-error-2">
        No
      </label>
    </div>
    
  </div>
  </fieldset>

</div>

The markup in story book is:

<div class="nhsuk-form-group nhsuk-form-group--error">
  <fieldset class="nhsuk-fieldset">
    <legend class="nhsuk-fieldset__legend">Have you changed your name?</legend>
    <div class="nhsuk-form-group nhsuk-form-group--error">
      <div class="nhsuk-hint" id="radios_7l6kx--hint">This includes changing your last name or spelling your name differently.</div>
      <span class="nhsuk-error-message" id="radios_7l6kx--error-message" role="alert">
        <span class="nhsuk-u-visually-hidden">Error: </span>Please select an option
      </span>
      <div class="nhsuk-radios" id="radios_7l6kx" aria-describedby="radios_7l6kx--hint">
        <div class="nhsuk-radios__item">
          <input class="nhsuk-radios__input" id="example-1" name="example" aria-labelledby="example-1--label" type="radio" value="yes">
          <label class="nhsuk-label nhsuk-radios__label" id="example-1--label" for="example-1">Yes</label>
        </div>
        <div class="nhsuk-radios__item">
          <input class="nhsuk-radios__input" id="example-2" name="example" aria-labelledby="example-2--label" type="radio" value="no" checked="">
          <label class="nhsuk-label nhsuk-radios__label" id="example-2--label" for="example-2">No</label>
        </div>
      </div>
    </div>
  </fieldset>
</div>

Issues:

  • The hint is not associated with the fieldset (though it is incorrectly associated with a div wrapping the two inputs)
  • The error message is not associated with anything

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions