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

Update inputs to show accessible names #2290

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

hnryjmes
Copy link
Contributor

@hnryjmes hnryjmes commented Jan 6, 2025

Aim

This PR makes some changes to resolve issues with accessible labels found in the most recent DAC report - these are listed in the ticket. The problems are generally that an input may appear to a screen reader but it's not clear what the input relates to.

As well as updating some for="" and aria-labelledby="" attributes to make clear what inputs relate to what hint text, the address input for UK based org registration has been updated. This was discussed in the ticket comments and it brings the UK based org registration form for address in line with the GDS design pattern (https://design-system.service.gov.uk/patterns/addresses/) by using "Address line 1" and "Address line 2" instead of "Building and street" and no label. The other inputs for address were also updated (along with the error messages) to keep things consistent with the Address example on the Design System page.

LTD-5172

@hnryjmes hnryjmes changed the title Update input labels Update input labels to show accessible names Jan 6, 2025
@hnryjmes hnryjmes force-pushed the LTD-5172_Update_input_labels branch from 49f2000 to 695a636 Compare January 7, 2025 14:45
@hnryjmes hnryjmes marked this pull request as ready for review January 7, 2025 16:23
@hnryjmes hnryjmes changed the title Update input labels to show accessible names Update inputs to show accessible names Jan 7, 2025
@@ -27,4 +27,4 @@
</div>
<span class="govuk-hint">You can replace the uploaded file below:</span>
{% endif %}
<input id="{{ name }}" type="file" name="{{ name }}" accept='{{ accept|join:"," }}' />
<input aria-labelledby="span--hint" id="{{ name }}" type="file" name="{{ name }}" accept='{{ accept|join:"," }}' />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think aria-labbelledby should point to a class name and I can't see an element with this id (it would be a weird id as well).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the id I want to link to is here: id="span-{{ page.single_form_element.name }}-hint"
https://github.com/uktrade/lite-frontend/blob/dev/lite_forms/templates/form.html#L74

but when I viewed this in a browser it just showed as span--hint so I hardcoded that as the reference. presumably that template variable evaluates to nothing when this page is viewed.

actually it works to use aria-labelledby="span-{{ page.single_form_element.name }}-hint" so I'll update to use that instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But won't this still come out as span--hint. I'm viewing the fact that the {{ page.single_form_element.name }} is coming out as blank is a signal that something isn't quite right here and that span--hint is just the wrong thing to set it to.

I think I need to stare at what this is all doing first.

Can you show me an example of a page that you are fixing this for so I can see what is being rendered in context?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually. Found the link in the ticket I'm presuming this is solving for so I'll take a look at that.

Copy link
Contributor

@kevincarrogan kevincarrogan Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more I dig through this the more this makes me feel like this isn't the correct fix for this problem.

However there is a question around whether this is something we even want to fix considering this is lite_forms.

One problem that will manifest as a result of this change is that if there is a form that just has a single upload input then it's going to end up with a label and a span that it's aria-labelled-by points to and ultimately this is all a bit confusing because setting {{ page.single_form_element.name }} is almost always going to be a blank string and when it's not a blank string it will do the wrong thing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the suggestion that we should be using that description span as the label?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't need to be that span. the file input just needs some sort of explanation as to what it's for, and that seemed like a good one to choose, alternatively we could use the main heading on the page

Copy link
Contributor Author

@hnryjmes hnryjmes Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the example here, there is a <label> element which has the attribute for pointing to the file upload input element. https://design-system.service.gov.uk/components/file-upload/

my choice to use that description text was that it seemed like the closest thing to the example from the design system

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and the reason that I can't use a for attribute for the file upload and have to use aria-labelledby instead is because the template form.html has many purposes and is not necessarily just used for that file input)

Copy link
Contributor

@currycoder currycoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending Kevin's comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants