-
Notifications
You must be signed in to change notification settings - Fork 3.2k
docs(angular): document boolean input changes in the v10 migration guide #4744
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
Open
thetaPC
wants to merge
2
commits into
major-10.0
Choose a base branch
from
FW-7637
base: major-10.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,3 +13,37 @@ For a **complete list of breaking changes** from Ionic 9 to Ionic 10, please ref | |||||
| ::: | ||||||
|
|
||||||
| ## Getting Started | ||||||
|
|
||||||
| ### Angular | ||||||
|
|
||||||
| #### Boolean Inputs | ||||||
|
|
||||||
| Boolean inputs now declare an input transform, so attribute presence is an explicitly supported way to set them: | ||||||
|
|
||||||
| ```html | ||||||
| <!-- Both set `button` to `true` --> | ||||||
| <ion-item button></ion-item> | ||||||
| <ion-item [button]="true"></ion-item> | ||||||
| ``` | ||||||
|
|
||||||
| Declaring the transform also turns on type checking for these inputs, which Angular did not do before. The generated component wrappers declare no class fields, so Angular had nothing to check a binding against and accepted any value. A binding that passes something outside `boolean | string | null | undefined` now fails to compile. The common case is a truthiness binding on a number: | ||||||
|
|
||||||
| ``` | ||||||
| error TS2322: Type 'number' is not assignable to type 'string | boolean | null | undefined'. | ||||||
| ``` | ||||||
|
|
||||||
| Coerce the expression to a boolean: | ||||||
|
|
||||||
| ```diff | ||||||
| - <ion-item [button]="items.length"></ion-item> | ||||||
| + <ion-item [button]="items.length > 0"></ion-item> | ||||||
| ``` | ||||||
|
|
||||||
| Coercion also moves from Stencil to Angular, which changes the result for numbers. `0` and `NaN` previously became `false` and now become `true`, matching Angular's own `booleanAttribute`. Without `strictTemplates` there is no compile error to catch the binding above, so an empty list now disables the item rather than enabling it. Coercing the expression fixes both the type error and the runtime change. | ||||||
|
Member
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.
Suggested change
This is the same correction as the one on the framework PR, since the paragraph came across with it. The example binds |
||||||
|
|
||||||
| `null` and `undefined` are passed through rather than coerced to `false`. This is deliberate, and it differs from Angular's own `booleanAttribute`, which turns both into `false`. Ionic components frequently treat "not set" as a third state distinct from `false`: | ||||||
|
|
||||||
| - `ion-item` falls back to the theme default for the detail arrow when `detail` is `undefined`, and hides the arrow when `detail` is `false`. | ||||||
| - A sheet `ion-modal` shows the drag handle unless `handle` is exactly `false`. | ||||||
|
|
||||||
| Both values reach inputs routinely, from the `async` pipe before its first emission and from form control values, so coercing them would silently change which of those branches runs. | ||||||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This holds under
strictTemplates, though the caveat doesn't turn up until the coercion paragraph further down, where it's attached to a different point. Could it go here instead? Someone withoutstrictTemplatesreads this, expects a compile error, gets none, and never reaches the part that actually affects them.