fix(runtime): correct boolean attribute handling for form-associated components #6280
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.
What is the current behavior?
GitHub Issue Number: #5461
Currently, form-associated Stencil components incorrectly handle boolean attributes like
disabled
. Whendisabled="false"
is set on a form-associated component, Stencil parses the string"false"
as booleanfalse
, which then gets reflected back to the DOM as thedisabled
attribute. According to HTML specification, for form-associated elements, the mere presence of boolean attributes likedisabled
(regardless of their value) should disable the element.This causes form-associated components to behave incorrectly when
disabled="false"
is explicitly set, as the component remains disabled when it should be enabled.What is the new behavior?
For form-associated components, boolean attribute parsing now follows HTML specification:
"false"
) is parsed as booleantrue
""
is parsed as booleantrue
false
) continue to work as expectedFor non-form-associated components, the legacy behavior is preserved:
"false"
continues to be parsed as booleanfalse
true
This ensures form-associated components behave correctly according to HTML standards while maintaining backward compatibility for existing non-form-associated components.
Documentation
No documentation changes required - this is a bug fix that aligns existing behavior with HTML standards.
Does this introduce a breaking change?
This is a bug fix that corrects incorrect behavior. Non-form-associated components maintain their existing behavior, ensuring backward compatibility.
Testing
parsePropertyValue()
function to accept an optionalisFormAssociated
parametersrc/runtime/set-value.ts
src/runtime/proxy-component.ts
src/runtime/client-hydrate.ts
src/hydrate/platform/proxy-host-element.ts
disabled="false"
by not setting the disabled attribute when the property value isfalse
Other information
This fix specifically addresses the issue where form-associated custom elements with
disabled="false"
would incorrectly remain disabled due to improper boolean attribute parsing. The solution follows HTML specifications while preserving existing behavior for non-form-associated components.Key technical changes:
parsePropertyValue()
with form-associated component detection