Opened 4 days ago
Last modified 3 days ago
#35870 assigned Cleanup/optimization
Allow customization of the blank option in select dropdowns
Reported by: | Marijke Luttekes | Owned by: | Thibaud Colas |
---|---|---|---|
Component: | Forms | Version: | 5.0 |
Severity: | Normal | Keywords: | accessibility |
Cc: | Marijke Luttekes | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Select dropdown inputs (<select>
) may have an empty first choice meant to leave a blank value or inform the user that they need to pick an option.
The default current value for this option is "---------"
and cannot be customized for the entire project at once. A developer must override each form field individually if they wish to change this value on their website, which is tedious and prone to errors.
The empty choice value is defined as BLANK_CHOICE_DASH
in django.db.models.fields.
Accessibility
The current blank option is also inaccessible; I quote this description from a private ticket that was assigned to me, and therefore cannot be linked directly:
Problem
Whenever a <select> dropdown has no option selected by default, a line of dashes is used inside of an <option>. The majority of screen reader/speech synthesiser combinations don't speak this, and so it can be confusing to hear essentially nothing. This is particularly true when navigating to the first choice from an option with text.
Solution
Use a more perceivable placeholder string for the first option, e.g. "(select an option)", using parentheses to disrupt first-letter keyboard navigation as little as possible.
Proposed change
I foresee two options:
- Replace
BLANK_CHOICE_DASH
with a new, optional setting, which allows users to set the blank option for their project. For backwards compatibility, the default value of the new setting equals"---------"
. - Replace
BLANK_CHOICE_DASH
with a new, more descriptive value in core.
Option 1 will be less disruptive, as this will not break existing behaviors. Option 2 will fix this problem for all users, but it would require translations for every language we offer.
Change History (11)
comment:1 by , 4 days ago
Description: | modified (diff) |
---|---|
Summary: | Allow customization of the empty option in select inputs → Allow customization of the blank option in select dropdowns |
comment:2 by , 4 days ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 4 days ago
Thanks, Carlton! I agree with using FORM_RENDERER
to set a default value and also allow a user to override it in settings.
I have asked Thibaud if he wants to use this one for Djangonaut Space session 3. If not, I will pick it up.
comment:4 by , 4 days ago
Looking good :) I’ve started doing screen reader testing. Will report back once my testing is completed. This is so I can quantify this more precisely:
The majority of screen reader/speech synthesiser combinations don't speak this, and so it can be confusing to hear essentially nothing. This is particularly true when navigating to the first choice from an option with text.
Regarding the two options – the experience of the Django admin’s end users should take priority over that of Django developers, and contributors (translators). So if this is a problem for most screen reader users, it should be treated as a bug and fixed in the framework and fixed there so Django is accessible out of the box.
comment:5 by , 4 days ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:6 by , 4 days ago
The options are not mutually exclusive, so I'd go for both.
Please take extra note of this part of the description:
[…] "(select an option)", using parentheses to disrupt first-letter keyboard navigation as little as possible.
The use of parentheses is essential to the new label.
(This feedback was provided by James Scholes, who is blind and an accessibility expert)
comment:7 by , 4 days ago
Not sure the monkey patch approach works...
It's used like this at class definition time...
def get_choices( self, include_blank=True, blank_choice=BLANK_CHOICE_DASH, limit_choices_to=None, ordering=(), ):
... so the blank_choice
default is set before any monkey patch can apply.
Sorry for the bum lead there, 'twas but a hunch.
comment:8 by , 4 days ago
I confirm that additional work for translators is a non-issue.
How about going to the Forum to obtain best practices for an accessible empty select option?
Could aria-label
usage help here?
comment:9 by , 4 days ago
How about going to the Forum to obtain best practices for an accessible empty select option?
The person who suggested (select an option)
(James Scholes) is not only blind but also the head of accessibility of a company that specializes in inclusive design and accessibility. While I am not saying we shouldn't consult the forum, I highly value his professional opinion.
Could
aria-label
usage help here?
I advise against the use of aria-label
, as it has some issues. Most notably, translation tools like Google Translate ignore these attributes completely. Alternatively, you can use aria-labelledby
and point it to an element with regular text contents. (The same goes for aria-description
versus aria-describedby
).
comment:10 by , 3 days ago
I'm not sure about screen reader support levels for aria-label
on <option>
. But I'd recommend against it for two other reasons:
Firstly, with mark-up like <option aria-label="(select an option)">-----</option>
, the accessible and visible labels would differ. WCAG auditors would probably disagree on whether that represented a failure of success criterion 2.5.3 (Label in Name), because the line of dashes is probably not a string that speech recognition users could speak out loud. Nevertheless, the actual name would be invisible.
This leads onto a more important second point: If developers were to override the default/placeholder text in code, Django would need to detect that and remove the aria-label
. Otherwise, setting e.g. blank_choice="None"
in Python would result in the HTML output <option aria-label="(select an option)">None</option>
. This would definitely be a WCAG SC 2.5.3 failure, and a concrete accessibility bug because it would affect meaning.
If aria-label
was only updated to match the defined default, it would arguably be an unnecessary use of ARIA at that point, with the potential problems described in aria-label is a code smell. In short, I think aria-label
would introduce unwarranted complexity in this case.
As to the specific text of the default option: It doesn't have to be in parentheses, e.g. MDN uses a string surrounded by dashes in some of their examples. But it should begin with some sort of punctuation that users are unlikely to type, to avoid it participating in the typeahead functionality provided by the browser. E.g. <option>Choose one...</option>
would receive focus when users typed the letter C. That may sometimes be what individual website developers want to happen, at which point they should be overriding the default anyway.
comment:11 by , 3 days ago
Thanks James for this precious input. Indeed, I'd be in favor of --select an option--
instead of (select an option)
, but I guess it's about personal taste…
The semantic issue I can see with such a change is that for non-required selects, it might imply that choosing an option is somewhat required. Not a blocker, just a thought.
Seems reasonable.
A couple of thoughts...
It's a module level constant so probably can be monkey patched as a workaround, in a settings file or a
AppConfig.ready()
:Given that this is form related, adding an attribute to the
FORM_RENDERER
would likely be a good candidate location, rather than a separate setting entirely.Using the form renderer would also give us a location for deprecation of the older option (if that is agreed on) as we did similar with the move to the
<div>
form templates, providing a fallback renderer during the deprecation period.I'll accept for both parts, assuming that *accessible by default* is a goal. Exact replacement for
-----
TBD.