11ty / 11ty/webc

Support dynamic :webc:is value

Open
#143 5 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
JavaScript
Stars
1.4k
Forks
46
Avg merge
10m
Merged PRs (30d)
2

Description

Hey! Doesn't seem like an urgent fix but...
This does not work properly (or at least not as I expected):

<div :webc:is="'my-component'" @test="Dynamic comp name does not pass props"></div>

The component renders but the test prop is not passed.

The workaround is probably to use a script.

<script webc:type="js">
  `<${"my-component"} @test="Template string comp name works"></${"my-component"}>`
  + // OR
  `<div webc:is="${"my-component"}" @test="Template string comp name works"></div>`;
</script>

Both work as expected.

My use case was the following:
I wanted to loop over an array of data with each entry containing the name of the component to be used and the props to be passed to said component.
I was trying something like this:

<div
  webc:for="block of blocks"
  :webc:is="block.tag"
  @attributes="block"
></div>

It looks super neat and compact! (but it does not work 😭😄)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the :webc:is examples in the issue, including the webc:for loop, and inspect the implementation that resolves dynamic component names. Done means a component selected from a dynamic value receives its @test or @attributes props, matching the script workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.