-
Notifications
You must be signed in to change notification settings - Fork 391
Reference Target: what type should the referenceTarget attribute be? #1093
Description
Originally posted by @dandclark in #1089
@alice To make sure I understand you, are you thinking that the
referenceTargetattribute's type should be a nullableDOMString?partial interface ShadowRoot { attribute DOMString? referenceTarget; }I had been assuming the attribute's type would just be
DOMString, and that's how it's prototyped today. But looking at the explainer again I guess it's not specific on this point.Assuming I'm reading the specs correctly, keeping it as a non-nullable
DOMStringtriggers this string conversion when trying to set the attribute to null, and this conversion happens before the implementation of the property "sees" the value:document.querySelector("#fancy-listbox").shadowRoot.referenceTarget = null; document.querySelector("#fancy-listbox").shadowRoot.referenceTarget; // logs 'null'But if we make it
DOMString?then we'd get the behavior you suggest. That's definitely seems like it'd avoid a pitfall when someone wants to clear the referenceTarget value. An inconsistency it introduces though is that theElement.idproperty is itself a non-nullableDOMString. So you get this today:const div = document.createElement("div"); div.id = null; div.id; // logs 'null'It's tempting to treat the
referenceTargetproperty as kind of equivalent to setting an ID elsewhere, so keeping the behavior consistent could be nice. What do you think? (Maybe this question should be its own thread.)