-
-
Notifications
You must be signed in to change notification settings - Fork 405
Component Boolean Arguments #407
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2069a00
Draft of component-boolean-arguments RFC
hakubo 63c33ff
fix typo
hakubo 5d2903e
rename file as it contained a typo
hakubo d1df5e3
attributes should also work the same way
hakubo 7a3074e
add note about that hacky solution is hacky, also attributes work as …
hakubo 49bf7cc
Update info about the alternatives
hakubo 8d6d88a
fix bullet points
hakubo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| - 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}} /> | ||
| ``` | ||
|
|
||
| ### Hacky "solution" | ||
| 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 /> | ||
| ``` | ||
| Since this is hacky, one have to remember that | ||
| ```hbs | ||
| <MyHackyBoolArgument @bool=false /> | ||
| ``` | ||
| would not work as `@bool=false` would pass a `false` as string that is truthy in JavaScript. | ||
|
|
||
| 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 an argument is passed without any value it should have a value `true` set inside of a component. | ||
|
|
||
| e.g. | ||
| ```hbs | ||
| <Button @secondary /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One possible drawback or unexpected consequence of this is that NOT passing |
||
| ``` | ||
| inside the Button component `@secondary` should equal to `true`. | ||
| e.g. | ||
| ```hbs | ||
| <button class={{if @secondary "is-secondary"}}> | ||
| Button | ||
| </button> | ||
| ``` | ||
hakubo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| should render as | ||
| ```html | ||
| <button class="is-secondary"> | ||
| Button | ||
| </button> | ||
| ``` | ||
|
|
||
| ### Align with attributes | ||
| This would align with how attributes behave currently. | ||
| Given an Input component: | ||
| ```hbs | ||
| <input ...attributes> | ||
| ``` | ||
|
|
||
| if it is invoked like this: | ||
| ```hbs | ||
| <Input disabled /> | ||
| ``` | ||
|
|
||
| it will 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 both React and Vue if a prop is passed with no value it is truthy inside of a component. | ||
| - https://vuejs.org/v2/guide/components-props.html#Passing-a-Boolean | ||
| - https://reactjs.org/docs/jsx-in-depth.html#props-default-to-true | ||
|
|
||
| ## Unresolved questions | ||
|
|
||
| None at the moment. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.