[whatwg] Questions and remarks about the labels attribute
ian at hixie.ch
Wed Jun 15 15:19:42 PDT 2011
On Thu, 31 Mar 2011, Mounir Lamouri wrote:
> I'm working on the labels attribute implementation in Gecko and I have a
> few remarks:
> * I wonder what are the use cases for authors. I see some use cases for
> browser vendors (a11y and UI for example) but what an author would do
> with that attribute?
It's an easy way to get to the label of a form control, e.g. to change its
class. For example, if you have a form expressed in a table, with labels
in one column and fields in another, and you want to highlight the label
of a control when the control is focused, you could just walk back up the
chain to the label and manipulate its class directly onfocus and onblur.
> * The labels attribute returns a NodeList but all elements in the list
> are HTMLLabelElement so an HTMLCollection sounds more appropriate,
> doesn't it? Though, I might miss a difference between these two
> collections. FWIW, Opera (only implementation AFAIK) returns an
HTMLCollection can be indexed by name, that's the difference. Labels don't
have names except their IDs, and it's not clear there's any point indexing
labels by ID since you could just get the element by ID directly.
> * The most important issue is related to the collection returned by the
> labels attribute. Given that the collection isn't stated to be static,
> it is live (according to DOM Core). Though, the root element of the
> collection might change: when an element is inside a document, it's
> always the document but when it is outside, it is the root of the
> fragment. One solution would be to explicitly say that labels can't
> labelize an element outside of a document even if it is the first
> labelled control descendant in the tree order. But how do we manage
> situations where .labels is returned when an element isn't in a document
> then the element is moved to a document? Should the root element of the
> collection change? Another solution would be to make the collection
> static. Thus, we return whatever seems appropriate depending on the
> element being in a document or not. This solution seems also saner
> because it prevents watching the entire document when .labels is used
> which is a bit of overkill. Actually, I think that only form.elements
> returns a collection that implies watching the entire document (because
> of the form attribute) all other collections uses a sub-tree.
Why is the root changing a problem?
Ian Hickson U+1047E )\._.,--....,'``. fL
http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,.
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
More information about the whatwg