Re: [whatwg] relationship between labeled control and label for :active and :hover pseudos

> On 10 Nov 2014, at 16:38, Boris Zbarsky <bzbarsky@MIT.EDU> wrote:
> 
> On 11/10/14, 9:23 AM, Florian Rivoal wrote:
>> that authors occasionally ask for by the ability to style the label based on the state of the labeled control
> 
> "The label", or "the labels"?
> 
> The problem of "hover the control if the label is hovered" is simple: the label already has a reference to the control it's labeling; when an element enters hover state you at worst have to deal with one other element (plus their ancestors) entering hover state.
> 
> And even that gets a bit complicated given the "ancestors" thing.
> 
> The backreference, however, is a one-to-many relationship, which makes things quite complicated, or fairly slow, or both, when multiple labels label the same form control.  So I would be a bit careful here.

You’re right, the relation is one-to-many, making the cost in this direction greater than in the other one.

That said, the labeled control also maintains a list of references to the associated labels, so there is no particular difficulty involved in finding them.

Also, while the relationship is indeed one-to-many, I expect that this is actually fairly rare for controls to actually have several, let alone many associated labels. Even when they do, it should be even more rare for these labels to have long ancestor chains that don’t merge quickly, and when they do merge the walk up the dom can be cut short, as there’s no need to continue if you find an ancestor that already has the state marked as on. Turning it back off is probably a bit more involved at the point where the ancestor chains merge, but this already has to be solved to deal with the label's and the control’s ancestor chains merging, and I don’t think going from 2 to n changes the nature of the problem.

All in all, while I agree this is potentially slower, I don’t think it will be significantly different in anything but pathological cases. Or am I missing a common pattern involving a control with many labels in a deeply nested dom, with mostly distinct ancestor chains?

 - Florian

Received on Tuesday, 11 November 2014 01:19:39 UTC