11ty / 11ty/webc

Scoped CSS properties overridden when multiple instances of same component

Open
#213 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I'm using JavaScript to generate scoped CSS based on props passed to the component.

For example, inside of _components/flex-box.webc:

<script webc:type="js" webc:is="style" webc:scoped>
` 
:host {
  display: flex;
  flex-direction: ${direction};
}
`
</script>

The problem is when multiple instances of the same component are on the same page.
Sharing the same CSS class, only the last styles apply.

For example, inside of index.webc:

<flex-box @direction="row"></flex-box>
<flex-box @direction="column"></flex-box>

flex-direction: column; would override flex-direction: row;, assigning the same property to both elements.

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 with _components/flex-box.webc and index.webc, then inspect how webc:is="style" with webc:scoped is processed when the same component appears more than once. Reproduce the two directions shown in the issue and compare the generated styles. Done means each flex-box instance retains its own prop-specific flex-direction.

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.