Skip to content

Conversation

tut-tuuut
Copy link
Contributor

@tut-tuuut tut-tuuut commented Apr 26, 2025

This PR to add the bare minimum of accessibility on the form to contact the DSF.

Basically, display labels in dedicated labels instead of using the placeholder attribute.

That helps:

  • users of screenreaders who rely on "accessible labels" for knowing what is expected;
  • users with some attention or cognition disorders who need to see what is expected while they are typing content in the field.

When I'll have the whole "translation" part figured out I will try to fix the send button label ("Send →"). Ideally I would like to have the → in an span with aria-hidden=true because it is decorative.

Screenshot 2025-04-26 at 11-59-07 Contact the Django Software Foundation Django

Copy link
Member

@bmispelon bmispelon left a comment

Choose a reason for hiding this comment

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

Wow, thanks for taking the time to submit this! 🙏🏻

Here's a (folded) screenshot of how that looks like (light mode):

Screenshot 2025-04-28 at 22-18-15 Contact the Django Software Foundation Django

I think the changes to move away from placeholder in favor of a real <label> are the way to go. I've left a suggestion for a simplification of the template.

As for the arrow in the send button, I remember @marksweb and me discussing it on his PR to make the site translatable and I was the one to suggest including the &rarr; into the translatable string, on the basis that some languages might want to invert the direction. But that's not something I'm very confident about so I'd be happy to be told that's not a good practice. Also, even though most of the site is marked for translation we currently don't have any infrastructure for it, so don't be afraid to make changes since it won't actually break anything in that regard.

Thanks again for sending this, and don't hesitate to open other accessibility-improvements PR! 🎸

<form action="." method="post" accept-charset="utf-8" class="form-input">
{% csrf_token %}
<p>
<label for="{{ form.name.id_for_label }}">{{ form.name.label }}</label>
Copy link
Member

Choose a reason for hiding this comment

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

You could use:

Suggested change
<label for="{{ form.name.id_for_label }}">{{ form.name.label }}</label>
{{ form.name.label_tag }}

It's not strictly equivalent since it will add a : after the label but I think that's not a bad change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I like this!

</p>
<p class="form-email">
<label for="{{ form.email.id_for_label }}">{{ form.email.label }}</label>
{% if form.email.errors %}<p class="errors">{{ form.email.errors.as_text }}</p>{% endif %}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I've seen something else that needs a fix: if form.email.errors is true, then you will have two nested <p>s, which will break something. I will fix it in this PR too.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yes, good catch! If we're ok using a <div> to wrap up the label+input+errors we could simplify the template a lot and use:

<div>{{ form.name.as_field_group }}</div>

@tut-tuuut tut-tuuut force-pushed the fix-accessibility-of-contact-form branch from 55a3c73 to 6936b83 Compare April 28, 2025 22:43
@tut-tuuut
Copy link
Contributor Author

I'll come back to this later (this week I hope?) to fix this nested <p> issue. I could use divs but it will lack semantics and need some styling, so I may need some sleep to get a better idea. :)

@tut-tuuut
Copy link
Contributor Author

For the send button, we could add the arrow in CSS generated content (like ::after) with an empty alternative text; then use :dir(ltr) to change the generated content in order to display a left arrow in that case. The browser support for this pseudo-class is not so bad, and if it breaks it's "only" a weird arrow in a button.

(Oh and to use ::after we'll need to change the input submit into a button.)

@tut-tuuut tut-tuuut force-pushed the fix-accessibility-of-contact-form branch from 4bbe83d to 262847b Compare May 1, 2025 10:06
@bmispelon
Copy link
Member

Thanks for making the changes, it's looking quite nice now:

Light mode (with errors)

Screenshot 2025-05-02 at 14-13-31 Contact the Django Software Foundation Django

Dark mode (with errors)

Screenshot 2025-05-02 at 14-13-48 Contact the Django Software Foundation Django

I find the styling of errors a bit jarring in dark mode, but I don't have a better proposal so I'll defer to you . If you're happy with how it looks, I'm happy to merge it. 🚢

@tut-tuuut
Copy link
Contributor Author

I tried to add the css-generated arrow in the "send" button, and then… things happened :D

<a href="https://forum.djangoproject.com">Django Forum</a>.
{% endblocktranslate %}
</p>
<form action="." method="post" accept-charset="utf-8" class="form-input">
Copy link
Contributor Author

@tut-tuuut tut-tuuut May 2, 2025

Choose a reason for hiding this comment

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

I removed this class "form-input" as it made the <button> move on top right of the form, apparently because of an ancient class (2014) not used anymore for its original purpose throughout the site.

Copy link
Member

Choose a reason for hiding this comment

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

an ancient class (2014) not used anymore for its original purpose throughout the site.

That's probably a good 20% of our CSS styles at this point 😭

@tut-tuuut tut-tuuut force-pushed the fix-accessibility-of-contact-form branch from d2c5a4e to 23a414c Compare May 2, 2025 14:55
@tut-tuuut
Copy link
Contributor Author

This is my final proposal: no update on error colors, I would like to compare with other colors through the website (currently it's not perfect but it was worse when the errors were not highlighted at all).

I added the styling with CSS-generated arrow on the "send" button, which adapts when the language is right-to-left.

LTR in white modeCapture d’écran 2025-05-02 à 16 56 21
LTR in dark modeCapture d’écran 2025-05-02 à 16 56 45
Send button in RTL mode (using `dir="rtl"` on root html node)Capture d’écran 2025-05-02 à 16 59 31

@bmispelon
Copy link
Member

I like the CSS changes to remove the &rarr; from the button, but I think I'd prefer to have that in a separate PR so we can fix all the forms that use the same pattern (git grep -F '&rarr' shows 3 more instances). Are you OK with me merging the 3 first commits only?

.cta.arrow {
height: auto;
&::after {
content: "" / "";
Copy link
Member

Choose a reason for hiding this comment

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

Also this is cool, I didn't know about the / syntax for content 🤯

@tut-tuuut
Copy link
Contributor Author

I like the CSS changes to remove the &rarr; from the button, but I think I'd prefer to have that in a separate PR so we can fix all the forms that use the same pattern (git grep -F '&rarr' shows 3 more instances). Are you OK with me merging the 3 first commits only?

Yes, go for it 👍

@tut-tuuut tut-tuuut force-pushed the fix-accessibility-of-contact-form branch from 23a414c to 262847b Compare May 4, 2025 09:01
@tut-tuuut
Copy link
Contributor Author

I've extracted the 3rd commit into a dedicated PR @bmispelon so you can merge more easily. ❤️

@sabderemane sabderemane requested review from SaptakS and sabderemane May 4, 2025 13:40
@marksweb
Copy link
Contributor

marksweb commented May 5, 2025

I agree on a separate PR for moving arrows into css. It will make things much cleaner 👏👍

@bmispelon bmispelon merged commit 95ed0d5 into django:main May 6, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

4 participants