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

automatically propagate id and class on components to the element the component is bound to #280

Closed
monsanto opened this issue Nov 19, 2013 · 1 comment

Comments

@monsanto
Copy link
Contributor

I've been working on a Ractive component for the Ace editor. At the moment, if I want to style it with CSS, I have to manually proxy the id and class elements, so I can support syntax like

<ace id="foo" ... />

In my opinion, it would be more useful if these properties were automatically propagated to ractive.el (perhaps a setting could be added to turn off this behavior). Otherwise every component writer will have to manually proxy them so their components can be styled.

This would effectively make id and class "reserved attributes", but I would expect them to be anyway--if a component author repurposed these attributes that would be very confusing.

Thoughts?

@Rich-Harris
Copy link
Member

I think I see what you're getting at here - have I understood this correctly?

<ace id='foo' class='bar' content='{{whatever}}'/>

<!-- with a basic template this... -->
<div></div>

<!-- ...translates to something like this... -->
<div id='foo' class='bar'></div>

<!-- ...which after initialisation looks something like this -->
<div id='foo' class='bar ace_editor ace_nobold ace-twilight ace_dark'>
  <!-- ace editor controls the DOM in here -->
</div>

As opposed to having to have a template like this:

<div id='{{id}}' class='{{class}}'></div>

I'm a bit hesitant, for three reasons. Firstly, a component template could have several top-level elements - the class name could propagate, but the id couldn't, because then you'd have multiple elements with the same id. So there would need to be a set of rules about what should propagate where. Secondly, it adds a chunk of complexity - if a template element already has a class name (which might be dynamic), then making sure that it also includes whatever class name the component itself has (which again, might be dynamic) means adding a whole load of 'special case' logic.

Thirdly, it means adding complexity to the API (the id/class exception wouldn't be obvious, it would be one of those things that you have to learn about through documentation and remember) without adding new functionality (since id='{{id}}' may look clumsy, but works perfectly well).

So my inclination is to close this as wontfix, I'm afraid. Having said all that I do understand where you're coming from - do let me know if I've misunderstood the proposal or if you disagree with the points above.

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

2 participants