Skip to content
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

Add global reflecting attributes to ElementInternals? #821

Open
justinfagnani opened this issue Jun 27, 2019 · 3 comments
Open

Add global reflecting attributes to ElementInternals? #821

justinfagnani opened this issue Jun 27, 2019 · 3 comments

Comments

@justinfagnani
Copy link
Contributor

Since reflecting IDL attributes create HTML attributes on an element when set, and there may be cases where that's undesired, or even disallowed (setting attributes in a constructor) - should some or all of the global attributes have properties added to ElementInternals? And should global attributes going forward be added to ElementInternals?

A use case would be an element that wants to perform some initialize a value in a custom element constructor

class MyElement extends HTMLElement {
  constructor() {
    this.title = 'A Custom Element';
  }
}

This will report an error because the title attribute is created. I've seen people hit this with title and recently with ariaPressed in Safari. ariaPressed will be handled by ElementInternals, so should other attributes be to?

Looking at the current list of global attributes, including title (but excluding tabindex, which might be covered differently like in #762) I could possibly see arguments that they're not actually internal and should only be set externally, ie an element shouldn't sprout it's own tooltip, but I'm not sure if or how that's been rationalized yet.

@domenic
Copy link
Collaborator

domenic commented Jun 27, 2019

ElementInternals is for setting internal values. ariaPressed will be "handled" by ElementInternals, but not in the same way that setAttribute("aria-pressed", ...) does. Instead it will set the default aria-pressed semantic. (Maybe we should rename it defaultARIAPressed.)

The example code you give doesn't seem to be a use case; I'm unclear what it's saying. Is the author trying to use title, unaware that it's a reflecting setter? Are they trying to set the title attribute, but unaware that you're not supposed to do that in constructors? I think there are clear solutions for either of those use cases (e.g., use a different name, or use connectedCallback, respectively) that don't require new spec and implementation work on ElementInternals.

So in general I agree with your last paragraph; the global attributes are generally not internal things (like default ARIA semantics are) and it doesn't make much sense to put them on ElementInternals.

@justinfagnani
Copy link
Contributor Author

justinfagnani commented Jun 27, 2019

The example code you give doesn't seem to be a use case; I'm unclear what it's saying. Is the author trying to use title, unaware that it's a reflecting setter? Are they trying to set the title attribute, but unaware that you're not supposed to do that in constructors?

I think the intent was just to add a tooltip, and the title attribute is the mechanism available. Is that something that should always be done via title attribute? If so, and if attribute are for external uses, does that imply that custom elements should never add tooltips to themselves?

If that's not the conclusion, then is the correct way to do this to set the title attribute in connectedCallback, or is this the kind of thing where there should also be an internal default, overridable by the public attribute?

edit: defaultARIAPressed does sound clearer for its purpose.

@rniwa
Copy link
Collaborator

rniwa commented Jun 27, 2019

The example code you give doesn't seem to be a use case; I'm unclear what it's saying. Is the author trying to use title, unaware that it's a reflecting setter? Are they trying to set the title attribute, but unaware that you're not supposed to do that in constructors?

I think the intent was just to add a tooltip, and the title attribute is the mechanism available. Is that something that should always be done via title attribute? If so, and if attribute are for external uses, does that imply that custom elements should never add tooltips to themselves?

Just adding a tooltip is a misguided way of thinking about title content attribute. But that aside, given there is no builtin element which sets title content attribute or any sort of default for its advisory information, I don't think custom elements implementations should do it either. title content attribute should be set by the users of custom elements instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants