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

Cant set attributes #68

Closed
emattias opened this issue Oct 27, 2021 · 3 comments
Closed

Cant set attributes #68

emattias opened this issue Oct 27, 2021 · 3 comments

Comments

@emattias
Copy link

emattias commented Oct 27, 2021

I wanted to yield a span from a general component and set some classes and maybe other attributes on the span for consumers of the general component. Something like this:

{{yield
  (hash
    Foo=(element "span" class="truncate")
  )
}}

But its explicitly not allowed. How come? And could it be changed to be allowed?

@SergeAstapov
Copy link
Contributor

@emattias to pass class name, you may try

{{yield
  (hash
    Foo=(component (element "span") class="truncate")
  )
}}

Other attributes can't be passed in and it's not limitation of this addon but rather a limitation of Ember.js at this point of time, see for more info emberjs/rfcs#497

@angelayanpan
Copy link

component helper seems to be adding @ to class

@NullVoxPopuli
Copy link
Collaborator

I do this in ember-primitives this way:

const Span = <template>
  {{#let (element 'span') as |el|}}
    <el class="truncate" ...attributes>
      {{yield}}
    </el>
  {{/let}}
</template>;

<template>
  {{yield (hash
    Foo=Span
  )}}
</template>   

Gonna close because this is more a general composition thing that only really got more ergonomically possible with gjs.

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

4 participants