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

Feature request: support extending native elements with controller decorator #148

Closed
HipsterBrown opened this issue May 17, 2021 · 2 comments

Comments

@HipsterBrown
Copy link

First off, I'm really enjoying this library, so thanks for sharing it! It's been a great transition into custom elements from Stimulus development.

In some recent work, I wanted to extend a native element, HTMLAnchorElement in this case, when building my catalyst-controlled custom element. I ran into a roadblock when using the @controller decorator because it doesn't have a way to specify the extends option.

This could be done manually by the author:

@controller({ extends: 'a' })
class CustomLinkElement extends HTMLAnchorElement {
}

Or inferred by the library code when defining the element:

const ElementMap = {
  'HTMLAnchorElement': 'a',
 ...etc
};

// register.ts
let extends = ElementMap[Object.getPrototypeOf(classObject).name];
window.customElements.define(name, classObject, { extends });

I like the ability extend native elements in order to limit the extraneous markup to add functionality, but I understand if this feels out of scope for a stimulus-type replacement.

@koddsson
Copy link
Contributor

I understand if this feels out of scope for a stimulus-type replacement.

It's probably not strictly out of scope, but we have some we don't extend any built-in elements in our codebases for a few reasons that are documented in this eslint rule. The takeaways are:

For those reasons, I don't see us adding support for extending built-in elements at this time.

@HipsterBrown
Copy link
Author

@koddsson Thanks for the explanation. I wasn't aware of the Safari support issue. 👍

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

Successfully merging a pull request may close this issue.

2 participants