|
| 1 | +# ember/template-builtin-component-arguments |
| 2 | + |
| 3 | +<!-- end auto-generated rule header --> |
| 4 | + |
| 5 | +✅ The `extends: 'recommended'` property in a configuration file enables this rule. |
| 6 | + |
| 7 | +The builtin `Input` component has several arguments that match attributes |
| 8 | +of the lower-case `input` HTML element. These arguments should be set via e.g. |
| 9 | +`@type`, instead of `type`, but it is easy to forget and can cause subtle |
| 10 | +issues. |
| 11 | + |
| 12 | +This rule warns about `Input` component invocations that use the following attributes instead of arguments: |
| 13 | + |
| 14 | +- `checked` |
| 15 | +- `type` |
| 16 | +- `value` |
| 17 | + |
| 18 | +The builtin `Textarea` component has several arguments that match properties |
| 19 | +of the lower-case `textarea` HTML element. These arguments should be set via e.g. |
| 20 | +`@value`, instead of `value`, but it is easy to forget and can cause subtle |
| 21 | +issues. |
| 22 | + |
| 23 | +This rule warns about `Textarea` component invocations that use the following attributes instead of arguments: |
| 24 | + |
| 25 | +- `value` |
| 26 | + |
| 27 | +Please note that this rule currently only warns about these three attributes on |
| 28 | +the `Input`, and one property on the `Textarea` components, but might be extended in the future to also warn about |
| 29 | +other attributes or builtin components. |
| 30 | + |
| 31 | +## Examples |
| 32 | + |
| 33 | +This rule **forbids** the following: |
| 34 | + |
| 35 | +```hbs |
| 36 | +<Input type='text' size='10' /> |
| 37 | +``` |
| 38 | + |
| 39 | +```hbs |
| 40 | +<Input @type='checkbox' checked /> |
| 41 | +``` |
| 42 | + |
| 43 | +```hbs |
| 44 | +<Textarea value="Hello, Tom!" /></Textarea> |
| 45 | +``` |
| 46 | + |
| 47 | +This rule **allows** the following: |
| 48 | + |
| 49 | +```hbs |
| 50 | +<input type='text' size='10' /> |
| 51 | +``` |
| 52 | + |
| 53 | +```hbs |
| 54 | +<Input @type='text' size='10' /> |
| 55 | +``` |
| 56 | + |
| 57 | +```hbs |
| 58 | +<Input @type='checkbox' @checked={{true}} /> |
| 59 | +``` |
| 60 | + |
| 61 | +```hbs |
| 62 | +<Textarea @value="Hello, Tom!" /></Textarea> |
| 63 | +``` |
| 64 | + |
| 65 | +## Migration |
| 66 | + |
| 67 | +- Add the `@` character in front of the relevant attributes to convert them |
| 68 | + into component argument |
| 69 | + |
| 70 | +## Related Rules |
| 71 | + |
| 72 | +- [template-no-unknown-arguments-for-builtin-components](template-no-unknown-arguments-for-builtin-components.md) |
| 73 | + |
| 74 | +## References |
| 75 | + |
| 76 | +- [`Input` component API documentation](https://api.emberjs.com/ember/release/classes/Ember.Templates.components/methods/Input?anchor=Input) |
| 77 | +- [`Textarea` component API documentation](https://api.emberjs.com/ember/release/classes/Ember.Templates.components/methods/Textarea?anchor=Textarea) |
0 commit comments