-
Notifications
You must be signed in to change notification settings - Fork 50
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: attrs without data-
prefix
#215
Comments
Thanks for the issue @onEXHovia! I think your idea has some merit, but I am not sure the prefix is totally redundant for custom elements. Custom Elements will inherit attributes from the element they inherit, which includes Aria attributes, the Global attributes like @controller
class FooBar extends HTMLElement {
@attr slot = 1
} ^ If this element was defined prior to The problem gets more complex when we talk about extending built in elements (which is something Catalyst doesn’t do yet, but may do in the future). The potential for clobbering attributes gets a lot higher: @controller
class FooBar extends HTMLInputElement {
@attr autocomplete = ‘foo’ // Oops! Accidentally clobbered input[autocomplete] semantics!
} Part of the purpose of Catalyst is to guide web component authors to the right path. Having However I do think there’s something to pick at here… the ergonomics of |
Thank you for such a quick answer, I partly agree with you, but all the examples that have been described are not a problem of catalyst, but authors web components. It seems to me such problems can be described in the documentation. Still, the configuration of this behavior would be useful. |
It kind of becomes a problem of catalyst, as it is expressly designed to guide authors to the right choices. In the case of I think there are a few of things I want to pull out of this though:
I'd like to work hard to avoid configuration, and so having an opt out of |
Reading any documentation on custom elements, the examples almost always setting attributes html without the Since Catalyst extends the capabilities of web components, it was strange for me to see recommendations for setting attributes via |
Upon reflecting on this, and looking at the list of existing HTML attribute names, and to see if we could find I happy medium, I think I’m more on board with dropping the
|
Using the example of @controller
class AutocompleteElement extends HTMLElement {
@attr src: string;
@attr for: string;
} Perhaps we should not try to solve this problem for the developer, but inform him or throw an exception if he tries to define a property from the prototype. I'm not sure how much this is possible, but |
Appreciate the feedback, and I think you've listed two great examples of attributes which have specific built in semantics, which we'd like Catalyst components to respect, and so we're working to make "Abilities" (mixin decorators) which provide mechanisms that align tightly to the existing DOM specs. These abilities can then be dropped in to Controller, so these might look something like: /*
The forable mixin:
- adds `htmlFor` property (mapping to `for` attribute)
- watches for `for` attribute changes.
- calls `forElementChangedCallback` with the new for element
*/
import {forable} from '@github/catalyst'
/*
The loadable mixin:
- adds `src` and `loading` property
- watches for `src` and `loading` attribute changes.
- calls `load()` when `src` changes (if connected)
- calls load on `connectedCallback` if `loading=eager`
- calls load when visible if `loading=lazy`
- `load()` calls get debounced to microtask
- emits `loadstart, `load`, `loadend`, and `error` events, where appropriate
*/
import {loadable} from '@github/catalyst'
@forable
@loadable
@controller
class AutoCompleteElement extends HTMLElement {
forElementChangedCallback(newForElement: Element) {
this.htmlFor // returns '#for'
}
load(request: Request) {
}
} This way we get the best of both worlds: full flexibility with |
@keithamus looks great, its would be useful. Wanted continue the discussion on the name properties of 2 words with an example document.addEventListener('click', (event: Event) => {
....
const target = event.target.closest('route-page');
if (target instanceof RoutePageElement) {
target.forward();
}
});
@controller
class RoutePageElement extends HTMLElement {
@attr path: string;
forward(): void {
window.location.href = this.path;
}
} Attribute |
At the risk of pedantry I think with a little creative naming one should be able to work around the limitation, for example in this case |
An example of webcompat issues with the addition of new global attributes that cause issues is the new popup attribute, which caused webcompat issues with Jira which used the property. This is good motivation for us to avoid clobbering global properties. |
I agree that overriding global or native properties should be avoided, can this be worked around by simply throwing an error (with a helpfully specific message) if a property with the attr's name already exists on the component? It would then be up to the library consumer to resolve the conflict. Warnings about potential naming conflicts could also be added to the documentation, possibly including links to cases like the above Jira incident, to educate developers about the risks. |
The problem with that is that we don't know what new attributes are to be introduced. In the case of popup, it was a new attribute that doesn't exist in the ecosystem right now. |
Hmm, good point. My thought was a runtime check to see if a property exists on the DOM element, but that wouldn't cover possible attributes. And there doesn't seem to be a way to get a list of possible attribute names for an element or element type, short of looking at the spec. Sigh. |
👋 It would be great if it was in the kernel,
data
prefix is redundant for custom elements.The text was updated successfully, but these errors were encountered: