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

A slot entry must be a direct child of a component #1870

Closed
aymanosman opened this issue Feb 4, 2022 · 5 comments
Closed

A slot entry must be a direct child of a component #1870

aymanosman opened this issue Feb 4, 2022 · 5 comments

Comments

@aymanosman
Copy link
Contributor

Given

<.alert>
  <%= for error <- @errors do %>
   <:error>
     Some Error <%= error %>
   </:error>
  <% end %>
</.alert>

I get the following error message.

invalid slot entry <:error>. A slot entry must be a direct child of a component

I'm just wondering whether there is a plan to support such a use-case because it would be neat.

@thiagomajesk
Copy link
Contributor

thiagomajesk commented Feb 7, 2022

Hi @aymanosman! Wouldn't this example yield the same result for your use case?

def alert(assigns) do
  ~H"""
  <div class="alert alert-danger">
    <ul>
       <%= for error <- @errors do %>
         <li><%= render_slot(error, error) %></li>
       <% end %>
     </ul>
  </div>
  """
end
<.alert errors={["really bad error message"]}>
  <:error let="error">
    Some Error <%= error %>
  </:error>
</.alert>

@chrismccord
Copy link
Member

Confirm, @thiagomajesk is the solution to achieve what you want. Thanks!

@aymanosman
Copy link
Contributor Author

That works! Thanks.

There was just a small typo in your example.

This let="error" should be let={error}

@ssbb
Copy link

ssbb commented Feb 8, 2022

Just to confirm - there is no plans to allow this behaviour so it's by design or just temporary limitation until it will be done?

Like in <.table> component example from docs - if I need to hide column based on some conditions. I can just pass something like <:col show={...}> and hide it inside table component - is it a way to go?

@chrismccord
Copy link
Member

confirm

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