feat(fast-html): support boolean attributes that have conditions#7330
Open
mohamedmansour wants to merge 5 commits intomicrosoft:mainfrom
Open
feat(fast-html): support boolean attributes that have conditions#7330mohamedmansour wants to merge 5 commits intomicrosoft:mainfrom
mohamedmansour wants to merge 5 commits intomicrosoft:mainfrom
Conversation
janechu
requested changes
Mar 20, 2026
| <head> | ||
| <meta charset="utf-8" /> | ||
| <title></title> | ||
| <script type="module" src="./main.ts"></script> |
Collaborator
There was a problem hiding this comment.
This script should not be in the head, can we place this back to the end of the body?.
|
|
||
| class TestBoolCondition extends FASTElement { | ||
| @attr({ attribute: "active-group" }) | ||
| activeGroup: string = ""; |
Collaborator
There was a problem hiding this comment.
Just as a precaution, I think these strings should be different between the activeGroup and currentGroup so that we don't get false positives.
| type | ||
| ); | ||
| // Check if the value is a comparison expression (e.g., "activeGroup == item") | ||
| const expressionChain = getExpressionChain(propName); |
Collaborator
There was a problem hiding this comment.
Feels like we should update the expressionResolver to resolve regular access paths if it does not already and simplify this to just call the expressionResolver without an if/else check.
Co-authored-by: Jane Chu <7559015+janechu@users.noreply.github.com>
Co-authored-by: Jane Chu <7559015+janechu@users.noreply.github.com>
Co-authored-by: Jane Chu <7559015+janechu@users.noreply.github.com>
5 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds support for boolean attributes with comparison expressions in
@microsoft/fast-html. Previously, attribute bindings only supported simple property access (e.g.,{{type}}). Now, expressions like?data-active="{{activeGroup == currentGroup}}"are correctly resolved — the boolean attribute is toggled based on the result of the comparison.Changes
template.ts— When processing attribute bindings, the code now checks if the value is a comparison expression (viagetExpressionChain). If the operator is not a simple"access", it routes throughexpressionResolverinstead ofbindingResolver, enabling condition evaluation for attributes.attribute.spec.ts— Added a new Playwright test ("boolean attribute with comparison condition") that validates the attribute is present when the condition is true, removed when the condition becomes false, and re-added when it becomes true again.index.html— Added atest-bool-conditionfixture using?data-active="{{activeGroup == currentGroup}}"with pre-rendered SSR shadow DOM.main.ts— RegisteredTestBoolConditioncomponent withactiveGroupandcurrentGroupobserved attributes.What still works with attributes
type="{{type}}"continue to use the existingbindingResolverpath — no behavior change.disabledstatic attribute still renders correctly.data-fe-b-*markers hydrate as before.