Skip to content

Commit 08415f0

Browse files
committed
Sync with ember-template-lint
1 parent 152939b commit 08415f0

1 file changed

Lines changed: 36 additions & 29 deletions

File tree

docs/rules/template-no-splattributes-with-class.md

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,59 @@
22

33
<!-- end auto-generated rule header -->
44

5-
Disallow using `...attributes` with `class` attribute.
6-
7-
When using `...attributes` (splattributes), any classes passed from the parent component will be automatically merged with the component's own classes. Adding a `class` attribute alongside `...attributes` can lead to confusion about which classes take precedence.
5+
This rule enforces that when using `...attributes` (spread attributes), you should not also use a `class` attribute. The `...attributes` syntax is used to forward HTML attributes from a parent component to a child component, and it already handles class merging automatically.
86

97
## Examples
108

119
This rule **forbids** the following:
1210

13-
```gjs
14-
<template>
15-
<div ...attributes class='foo'>
16-
content
17-
</div>
18-
</template>
11+
```hbs
12+
<div ...attributes class='foo'>
13+
content
14+
</div>
1915
```
2016

21-
```gjs
22-
<template>
23-
<div class='foo' ...attributes>
24-
content
25-
</div>
26-
</template>
17+
```hbs
18+
<div class='foo' ...attributes>
19+
content
20+
</div>
2721
```
2822

2923
This rule **allows** the following:
3024

31-
```gjs
32-
<template>
33-
<div ...attributes>
34-
content
35-
</div>
36-
</template>
25+
```hbs
26+
<div ...attributes>
27+
content
28+
</div>
3729
```
3830

39-
```gjs
40-
<template>
41-
<div class='foo'>
42-
content
43-
</div>
44-
</template>
31+
```hbs
32+
<div class='foo'>
33+
content
34+
</div>
4535
```
4636

4737
## Why?
4838

49-
When using `...attributes`, classes are automatically merged from parent components. Using a `class` attribute alongside it creates confusion about which classes take precedence and can lead to unexpected styling behavior.
39+
When using `...attributes`, any classes passed from the parent component will be automatically merged with the component's own classes. Adding a `class` attribute alongside `...attributes` can lead to confusion about which classes take precedence and may result in unexpected styling behavior.
40+
41+
For example:
42+
43+
```hbs
44+
{{! Parent component }}
45+
<MyComponent class='parent-class' />
46+
47+
{{! MyComponent template }}
48+
<div ...attributes class='child-class'>
49+
{{! This is confusing: which class takes precedence? }}
50+
</div>
51+
```
52+
53+
Instead, you should either:
54+
55+
1. Use `...attributes` alone to allow class merging from the parent
56+
2. Use `class` alone if you want to enforce specific classes
5057

5158
## References
5259

53-
- [Ember.js Guides - Splattributes](https://guides.emberjs.com/release/components/component-arguments-and-html-attributes/#toc_html-attributes)
60+
- [Splattributes](https://guides.emberjs.com/release/components/component-arguments-and-html-attributes/#toc_html-attributes) in the Ember.js guides

0 commit comments

Comments
 (0)