-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Make <label> elements reflect CSS pseudoclasses on associated form element #1632
Comments
From what I could find, the most compelling argument against came from @bzbarsky . I find that convincing and I understand the concern, but this is about hover and things that might be spammy. This is what led to my suggestion on www-style that excluding the potentially spammy things and re-proposing a simpler starting point - things like :focused and :checked specifically seem to be considerably rarer and easy to deal with and have the advantage of opening a host of new potential patterns for developers. |
This seems extremely useful and very naturally expressive on the one hand but seems to go against predictable structure on the other. I think most of the value would be from things like required/optional, valid/invalid, read-only. The things like hover, focus, and active both seem the least useful an the most likely to cause ambiguity. Perhaps it could only apply to psuedo-classes that a label itself cannot have? This would give most of the value without the ambiguity problem but introduces a slight consistency issue. |
I agree that for
|
I don't have a strong feeling for or against this. (I guess as a web developer, I think a better solution would be for :has() to work in both selector profiles, but I've been told many times that is not something implementers are interested in.) However , we had two implementers with objections in the linked thread, @bzbarsky and @rniwa. We can't put something in the standard with such implementer objections standing; we in fact need at least two implementers who are prepared to concretely commit to implementing it, and no strong objections. So, if people think this is a valuable change, the best thing they can do is to try to overcome the expressed implementer concerns, and furthermore to convince implementers to put it on their implementation roadmap. It sounds like some implementer representatives (from the CSSWG) in other parts of those engines would like this feature, so maybe there are some backchannel discussions to have there. Or people can use this bug to try to present their arguments, if they feel that's a productive use of their time. In any case, I'll tag this appropriately, and we'll see where the discussion goes. But I want everyone to be realistic about the chances of changing things here, and how the process works; we don't just standardize things and then the implementers must implement it :) |
Yes, they did push back. What makes this murky is that the same proposal had support from representatives of the same companies in the CSSWG. @bzbarsky's argument was based on the performance problems. While it is true that runtime cost of doing this from the button to the label is higher than in the other direction, this isn't overwhelming:
As for @rniwa's argument, I don't think it holds up, because he bases his rejection on “[...] this use case can be solved by the proposed |
@gregwhitworth: MS implemented button->label(s) matching of the :hover and :active states in IE 10 and 11, and during the discussion in the CSSWG, supported making that the standard behavior. As far as I can tell, this has been removed from Edge, though. Do you have any insight on why? Did you do that to align with the spec since the spec wouldn't align with you, or did you find some independent reason why this was problematic? |
The author part of me wants to shout "OMG yes, |
|
Would it be a feasible alternative to instead have a new combinator that works no matter how the label is applied? Eg. something like
|
@BigBadaboom We used to have a combinator for this, but it was dropped for reasons I don't remember. |
@LeaVerou I think you are thinking of 'friend' or the 'idref combinator' - discussions started in like '98 on that one and it changed names a few times. It's complicated, but I don't think that it would really have done exactly this. |
Sorry in advance for the long and somewhat side-issue comment, but one part of the discussion here raises a question that seems to generally be under-considered in working group deliberations...
Layout engines and performance are complicated; none of us are infallible. If @dbaron thinks this can be done reasonably, there's a good chance he's right. In fact, I expect it can be done reasonably, for some values of "reasonably". The basic performance cost here, in addition to the issues of propagating the change and dealing with non-local This is a general problem in the design of web specifications. There are lots of neat features we can add to the web platform (this one, So really, this is a question about tradeoffs. Which other things are you willing to give up, either for a few years due to slower implementation or permanently because no one can figure out how to make them work, to get a feature which increases complexity? How much performance degradation is OK before people just give up on the DOM entirely? Unfortunately, isolated working groups, and even individual rendering engine developers, are not typically well-positioned to think about these tradeoffs in the large. So we all stumble along, until a few years later we look back on the state of the world and wonder why everything is so slow and messy. None of these problems are specific to the Web, by the way; any complex software system will suffer from these sorts of problems. The Web somewhat exacerbates them by virtue of size and explicitly distributed decision-making. Note that it's not clear to me that suggested replacements for the proposed functionality, like
No easy answers here, I'm afraid. |
@bzbarsky does my suggestion from www-style which launched this discussion that we just do it for the rare event things like 'checked' and 'focus' help at all in this regard? it definitely seems simpler/less involved than things that could happen frequently or at any time like 'hover'? |
It's hard to say; it depends on whether someone then writes a benchmark that toggles checked state on thousands of checkboxes really fast, thus forcing UAs to optimize this case anyway. :( |
If my recollection is right, @dbaron did not show strong interest for this feature, but he did participate in the discussion, thought implementation would not be particularly problematic, and was persuaded (even if not enthusiastically so) that this was worth having.
As far as I understand,
True. I'll openly admit a personal bias in favor of expressiveness over performance (within reason), but I understand different people are at different points along that spectrum. All in all, I think it is a case of "can be done, is it worth the cost?", rather than a case of "cannot be done". |
The css-wg has (re)discussed this recently, and still think bidirectional propagation between labeled form controls and the corresponding label would be good. To the two reasons advanced against it by the whatwg:
So, all in all, while we realize the ball is in the whatwg camp, and that this is for you rather than us to define, our collective input remains that supporting this would be a good idea. |
Thanks for the update @frivoal. After refreshing myself on this issue, it seems like the main TODO is still in the camp of various CSSWG representatives from Apple and Mozilla to convince @rniwa and @bzbarsky to withdraw their implementer objections. Was there any progress on that front? Per #1632 (comment), I think we're generally happy to do this if there is implementer interest. |
I would like to hear back from @rniwa. My (extremely summarized) understanding of his argument was "we do not need this because we have As for @dbaron (or other mozillians) trying to convince @bzbarsky, I do not know if this discussion has occurred. |
Even if we did have |
@bzbarsky raises many good points. The only reason I mentioned The biggest question is if this feature really provides enough benefits to justify the extra complexity in browser engines as well as relevant specifications. For example, this feature would require the style engine to be able to check the state of another element in order to figure out whether a given pseudo element applies, and that each label element be able to efficiently find its associated form control element. Neither exists in WebKit, and implementing them would require a serious engineering effort. That's the engineering resource that could be diverted to implement other features and fix bugs elsewhere. |
There are a number of CSS pseudoclasses that reflect state of labelable elements. This includes the standard interactive pseudoclasses available on all elements (
:hover
,:active
,:focus
) and also form-specific pseudoclasses (:required
,:optional
,:invalid
,:valid
,:enabled
,:disabled
,:checked
,:selected
,:indeterminate
,:default
,:placeholder-shown
,:in-range
,:out-of-range
,:read-only
,:read-write
).The purpose of these pseudoclasses is to make it easy for the visual presentation to reflect the state. However, because there are only limited styling options available on most form elements, it is often desirable to convey the state by styling the label, instead, possibly using generated text content. For example, it is common to indicate a required form field with a red asterisk after the label.
Currently, in order to reflect the form element's state in the label with CSS, you must re-arrange the DOM order so that the label is a subsequent sibling in the tree (because CSS selectors only operate in tree order). For example, to create the "required" asterisk, you would need:
The HTML spec already requires that activation and hover interactions on the label should trigger the
:active
or:hover
state on the control. However, the reverse effect only happens if the control is a descendent of the label.In November 2014, the CSS WG resolved:
and also
Florian Rivoal reports that this resolution stalled at the WHATWG and nothing went forward.
I would strongly urge the HTML spec to require that implementations reflect all pseudoclasses from a labelled input onto the associated label element, for the following reasons:
<label>
element, enhancing accessibility.There may be reasons to make limited exceptions for certain pseudoclasses, such as
:defined
, where it could have a valid but distinct meaning on the label versus the control. But for the most part, the semantics of the label are the semantics of the element it describes.Edit: On re-reading Florian's email, it seems he did not mention anything about W3C HTML WG, so I'm not sure why I was thinking he did. False claims removed!
The text was updated successfully, but these errors were encountered: