-
Notifications
You must be signed in to change notification settings - Fork 378
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
Reference Target: Clarify how JS Element attributes work with referenceTarget #1066
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This explainer is getting closer and closer to spec text every time. Thanks for the added specificity!
These will _always_ refer to the **host** element that they're targeting, and _never_ the referenceTarget element directly. This behavior maintains the design that an [IDL attribute with type Element](https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes:element) can only refer to an element that is a descendant of a [shadow-including ancestor](https://dom.spec.whatwg.org/#concept-shadow-including-ancestor) of the element hosting the attribute. | ||
These will _never_ directly return the referenceTarget element that's inside the shadow tree. This is because an [IDL attribute with type Element](https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes:element) can only refer to an element that is a descendant of a [shadow-including ancestor](https://dom.spec.whatwg.org/#concept-shadow-including-ancestor) of the element hosting the attribute. | ||
|
||
Instead, most attributes return the **host** element that they're targeting, as long as the attribute's expected type is `HTMLElement`. However, The `.form` and `.list` attributes will return `null` when used with a referenceTarget, because they are expected to be `HTMLFormElement` or `HTMLDataListElement` and the host element itself is not a form or datalist. Importantly, the underlying association will still exist: the input will be connected to the form, for example; it's just not reflected by the `.form` attribute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a little odd, doesn't it? There is a form/list reference, and it's valid, but the JS accessor returns null
. Perhaps it'd be better to have the IDL for form
and list
return HTMLElement
(or even Element
?)?
I suppose there are likely web compat issues with this, of some variety.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree it seems odd. My main concern was worrying not to break the web by changing the return type to HTMLElement
instead of HTMLFormElement
/HTMLDataListElement
. That said, the change would only affect new scenarios that were previously not possible, and it should not affect existing code as far as I can tell. It would be good to have an expert weigh in on the potential problems with changing the IDL return types in the new scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to hold this PR for this feedback or open a new PR once we've heard from other implementors about possible issues here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would benefit from further discussion, but I don't think it should block this PR for now. I logged #1072 to discuss the follow-up options. Depending on the outcome of the discussion, another PR could be made to update this section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Thanks Ben!
Update the JavaScript attributes that reflect
Element
objects to clarify which attributes return the host element. Also, add special cases for the.form
and.list
attributes, which returnnull
because their types don't allow returning the host element.