- From: Alice <notifications@github.com>
- Date: Sun, 23 Feb 2025 17:52:16 -0800
- To: WICG/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <WICG/webcomponents/issues/1093/2677283669@github.com>
alice left a comment (WICG/webcomponents#1093) Here is an example of that distinction for `htmlFor` in the WebKit codebase (I've removed the referenceTarget logic for clarity): ```cpp RefPtr<HTMLElement> HTMLLabelElement::control() const { // An empty string value for `for` would cause this to return true if (!hasAttributeWithoutSynchronization(forAttr)) { for (auto& descendant : descendantsOfType<HTMLElement>(*this)) { if (descendant.isLabelable()) return const_cast<HTMLElement*>(&descendant); } return nullptr; } return isConnected() ? elementForAttributeIfLabelable(*this, forAttr) : nullptr; } ``` This is an implementation of this language in the HTML spec: > If the \[for\] attribute is specified and there is an element in the [tree](https://dom.spec.whatwg.org/#concept-tree) whose [ID](https://dom.spec.whatwg.org/#concept-id) is equal to the value of the [for](https://html.spec.whatwg.org/multipage/forms.html#attr-label-for) attribute, and the first such element in [tree order](https://dom.spec.whatwg.org/#concept-tree-order) is a [labelable element](https://html.spec.whatwg.org/multipage/forms.html#category-label), then that element is the [label](https://html.spec.whatwg.org/multipage/forms.html#the-label-element) element's [labeled control](https://html.spec.whatwg.org/multipage/forms.html#labeled-control). > > If the [for](https://html.spec.whatwg.org/multipage/forms.html#attr-label-for) attribute is not specified, but the [label](https://html.spec.whatwg.org/multipage/forms.html#the-label-element) element has a [labelable element](https://html.spec.whatwg.org/multipage/forms.html#category-label) descendant, then the first such descendant in [tree order](https://dom.spec.whatwg.org/#concept-tree-order) is the [label](https://html.spec.whatwg.org/multipage/forms.html#the-label-element) element's [labeled control](https://html.spec.whatwg.org/multipage/forms.html#labeled-control). -- Reply to this email directly or view it on GitHub: https://github.com/WICG/webcomponents/issues/1093#issuecomment-2677283669 You are receiving this because you are subscribed to this thread. Message ID: <WICG/webcomponents/issues/1093/2677283669@github.com>
Received on Monday, 24 February 2025 01:52:20 UTC