Skip to content
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

Component Boolean Arguments #407

Closed
wants to merge 7 commits into from
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions text/0000-component-boolean-arguments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
- Start Date: 11/30/2018
- RFC PR: (leave this empty)
- Ember Issue: (leave this empty)

# Component boolean Arguments

## Summary

This RFC proposes to add a boolean argument to components, that aligns with boolean attribute of regular DOM elements.

## Motivation

Currently to pass a boolean property to a component a developer has to explicitly pass `true` as an argument.
e.g.
```hbs
<Button @secondary={{true}} />
```
This does allow the value to be a variable e.g.

```hbs
<Dialog @visible={{this.visible}} />
```

If the value is not a variable `{{}}` can actually be ommited as a `true` string is truthy leading to somewhat easier to remember syntax of
```hbs
<MyHackyBoolArgument @bool=true />
```
hakubo marked this conversation as resolved.
Show resolved Hide resolved

For simple usecases it is verbose to write and does not align with HTML attributes like `disabled` of which value can be ommited as desribed in [HTML Spec](https://www.w3.org/TR/html5/infrastructure.html#sec-boolean-attributes)

## Detailed design

This RFC proposes that if argument is passed without any value it should have value `true` set inside of a component.

```hbs
<Form @disabled />
```
inside the Form component `@disabled` would equal to `true`.

This RFC also proposes that it should be possible to pass attributes without an explicit value e.g.

```hbs
<Input disabled />
```
hakubo marked this conversation as resolved.
Show resolved Hide resolved

and inside a component `...attributes` should also contain `disabled` attribute. e.g.

```hbs
<input ...attributes>
```
should render as:
```html
<input disabled>
```


## How we teach this

This should be included in guides and also should be easier to teach as it is inline with HTML spec for attributes.

## Drawbacks

Can't think of any at the moment.

## Alternatives

- In React if a prop is passed with no value it is truthy inside of a component.
- In Vue if a prop is passed with no value it is falsy inside of a component.

## Unresolved questions

None at the moment.