-
-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Scoped style does not work with multi-root child components #5446
Comments
It's by design, in my view. The scoped data property is only inherited onto single root nodes because the intended use case is to add layout styles for that root node. That doesn't make too much sense for a multi-root component.l, and could in fact have unintended side effects when the number of root nodes changes during the lifecycle of the child component. So for multi-root components, the right approach would be to add a wrapper element in the parent for layouting purposes. Provided that @yyx990803 confirms this I'd say we should make the docs more explicit about this. |
The sense is that multiple root elements may use classes: And I may need to apply styles to these classes. But I can't achieve this neither with :deep pseudo class nor without it: Adding or not adding v-bind="$attrs" also does not help: Here is an updated example: |
Our perspective is that it's not a good idea to break separation of concerns/responsibilities in this way, so we don't go out of our way to support it.
Yes, :deep doesn't work either in your specific example because it would need one element at least in the parent wrapping the children: working with a root element in App.vue
in this specific scenario where the parent has no elements of its own around <template>
<Comp class="$styles.section" style="background: yellow;" />
<Comp2 class="$styles.section" style="background: yellow;" />
</template>
<style module>
.section {
border: 2px solid blue;
}
</style> |
@LinusBorg from the comments is a bit unclear if you answered or understood this issue with multi-root components so I am going to give it a try to ask again because in my view this is a bug. Component with multi-root nodes cannot be styled from parent with
|
There's a difference between a bug and a limitation of a design/solution/feature, wether that limitation is for technical reasons or intentionally put in place.
|
@LinusBorg thank you for the detailed explanation. Make sense to me now why this is a limitation. Have a nice weekend |
This is necessary in order to style the button in FunctionButton due to vuejs/core#5446
This is necessary in order to style the button in FunctionButton due to vuejs/core#5446
I believe a parent component (P) should be able to consume a child component (C) without knowing if C is a single or multi-root component. If, in component P, we set some CSS class for C, the styles tied to that class should fall through C no matter the root plurality. In my opinion, That API is consolidated in the VUE design and should not be broken for multi-root components. That fallthrough behavior is a decision for C to control. If it is a simple single root element, that is already settled and working, in the other case of C being a multi-root component, the That makes de API predictable. Someone read this doc and goes one applying It is not my intention to trash the framework design. I love VUE and use it daily. I also acknowledge that it is common for technical challenges to limit capabilities. That said, if this behavior is permanent, I think it should be declared as a limitation in here and/or here |
Version
3.2.31
Reproduction link
sfc.vuejs.org/
Steps to reproduce
See preview here: sfc.vuejs.org/
What is expected?
First 3 divs should have blue border
What is actually happening?
Only first div has blue border
The text was updated successfully, but these errors were encountered: