Skip to content

Commit a3d6fe0

Browse files
fix: dded note about multi-root components
1 parent dfe4b5d commit a3d6fe0

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/guide/class-and-style.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ However, this can be a bit verbose if you have multiple conditional classes. Tha
123123

124124
> This section assumes knowledge of [Vue Components](component-basics.md). Feel free to skip it and come back later.
125125
126-
> TODO: revise this with multi-root components
127-
128-
When you use the `class` attribute on a custom component, those classes will be added to the component's root element. Existing classes on this element will not be overwritten.
126+
When you use the `class` attribute on a custom component with a single root element, those classes will be added to this element. Existing classes on this element will not be overwritten.
129127

130128
For example, if you declare this component:
131129

@@ -151,8 +149,6 @@ The rendered HTML will be:
151149
<p class="foo bar baz boo">Hi</p>
152150
```
153151

154-
> TODO: needs a check after https://github.com/vuejs/rfcs/blob/attr-fallthrough/active-rfcs/0000-attr-fallthrough.md is merged
155-
156152
The same is true for class bindings:
157153

158154
```html
@@ -165,6 +161,27 @@ When `isActive` is truthy, the rendered HTML will be:
165161
<p class="foo bar active">Hi</p>
166162
```
167163

164+
If your component has multiple root elements, you would need to define which component will receive this class. You can do this using `$attrs` component property:
165+
166+
```html
167+
<div id="app">
168+
<my-component class="baz"></my-component>
169+
</div>
170+
```
171+
172+
```js
173+
const app = Vue.createApp()
174+
175+
app.component('my-component', {
176+
template: `
177+
<p :class="$attrs.class">Hi!</p>
178+
<span>This is a child component</span>
179+
`
180+
})
181+
```
182+
183+
You can learn more about component attribute inheritance in [Component Props](component-props.html#non-prop-attributes) section
184+
168185
## Binding Inline Styles
169186

170187
### Object Syntax

0 commit comments

Comments
 (0)