-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Behaviour of option elements with hidden attribute #3063
Comments
Thanks for the report! I suspect this would affect I suspect what you are observing will be identical to when you use |
Now that you have mentioned the datalist element, I could have actually used that in my project to begin with! Yes, setting the CSS display property to "none" has the exact same effect in all 3 web browsers. In other words, no changes from using the hidden attribute in each browser. As I am not a professional web developer, I cannot comment on the intricacies of HTML elements with respect to the HTML specifications. I will note, however, that the behaviour of initially keeping the top-most option element visible while it has either hidden attribute or display style set to none, has the advantage that the option disappears after the user has made a selection. This effect is perhaps best used when a web developer wishes to use an option element to ask the user to select an option, when an option is required. The request would then disappear after an option is selected. In my personal opinion, hidden option elements should not be accessible through keystrokes. |
This is interesting indeed. Here's my analysis. What does
|
Thanks, Dominic. |
Came across this issue today and did some investigation so hopefully this will be helpful: Quickly, Chromium, Firefox and Webkit all behave differently here.
FWIW, I like Firefox's behavior here... it solves the problem I've seen developers face where a design calls for a collapsed select element to have a default cta value - e.g., "choose an option...", but they don't want it to appear in the exposed listbox of options. |
I have uncovered inconsistencies in the behaviour of option elements with the hidden attribute across popular used web browsers (Google Chrome, Firefox, Internet Explorer) . After having posted a bug report on Google Chrome, I am now wondering what the correct behaviour should be.
With Google Chrome, if the first/top-most option in the list has the hidden attribute applied, it is still displayed in the select element. Further, while hidden option elements are not displayed in the select element's item list, they are still accessible when typing matching characters on the keyboard, or using the arrow keys.
Firefox also continues to display the first/top-most option element (hidden), but does not allow hidden option elements to be accessed.
Internet Explorer 11 completely disregards the existence of the hidden attribute on option elements.
The W3C spec states:
"When specified on an element, it indicates that the element is not yet, or is no longer, directly relevant to the page's current state, or that it is being used to declare content to be reused by other parts of the page as opposed to being directly accessed by the user."
I have highlighted what I believe to be the most pertinent part of the statement. Accessibility. Theoretically, given this statement, a user should not be able to access the hidden data. In this context, a user should not be able to type their way to displaying an option element with the hidden attribute.
The spec also states:
"The hidden attribute must not be used to hide content just from one presentation — if something is marked hidden, it is hidden from all presentations, including, for instance, screen readers."
Taking this into account, if an element has the hidden attribute, then shouldn't it be hidden absolutely everywhere on a webpage, or not? Conversely, if something is visible on the screen, then why shouldn't a screen reader be able to read it?
A Google Chrome moderator has asked me to lodge a report, here. The moderator also mentioned the "ask-for-a-reset algorithm", but I am not sure how that applies to the behaviour in discussion.
So, is there an exception to the rule here, or should the meaning of something using the hidden attribute be redefined?
References to global hidden attribute:
W3C - https://www.w3.org/TR/2016/REC-html51-20161101/editing.html#the-hidden-attribute
WHATWG - https://html.spec.whatwg.org/multipage/interaction.html#the-hidden-attribute
The text was updated successfully, but these errors were encountered: