Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

christian-bromann
Copy link
Member

What is the current behavior?

GitHub Issue Number: #5461

Currently, form-associated Stencil components incorrectly handle boolean attributes like disabled. When disabled="false" is set on a form-associated component, Stencil parses the string "false" as boolean false, which then gets reflected back to the DOM as the disabled attribute. According to HTML specification, for form-associated elements, the mere presence of boolean attributes like disabled (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:

  • Any string attribute value (including "false") is parsed as boolean true
  • Empty string "" is parsed as boolean true
  • Non-string values (actual boolean false) continue to work as expected

For non-form-associated components, the legacy behavior is preserved:

  • String "false" continues to be parsed as boolean false
  • Other string values are parsed as boolean 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?

  • Yes
  • No

This is a bug fix that corrects incorrect behavior. Non-form-associated components maintain their existing behavior, ensuring backward compatibility.

Testing

  • Modified parsePropertyValue() function to accept an optional isFormAssociated parameter
  • Updated all call sites in:
    • src/runtime/set-value.ts
    • src/runtime/proxy-component.ts
    • src/runtime/client-hydrate.ts
    • src/hydrate/platform/proxy-host-element.ts
  • Verified the build completes successfully without errors
  • The fix ensures form-associated components properly handle disabled="false" by not setting the disabled attribute when the property value is false

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:

  • Enhanced parsePropertyValue() with form-associated component detection
  • Conditional boolean parsing logic based on component type
  • Maintained backward compatibility for existing components

…components

For form-associated components, boolean attributes like `disabled` should
follow HTML spec behavior where the presence of the attribute (regardless
of its value, including "false") makes the property `true`.

- Modified parsePropertyValue() to accept optional isFormAssociated parameter
- For form-associated components: any string attribute value becomes `true`
- Preserved legacy behavior for non-form-associated components
- Updated all parsePropertyValue() call sites to pass form-associated flag

Fixes #5461
@christian-bromann
Copy link
Member Author

I've published a dev release @stencil/[email protected], any feedback would be much appreciated!

@christian-bromann christian-bromann merged commit 7fe6372 into main Jun 11, 2025
76 checks passed
@christian-bromann christian-bromann deleted the cb/form-disabled-prop-fix branch June 11, 2025 02:40
@AlexanderYW
Copy link

Hi there,

I just wanted to point out that this change does appear to have introduced breaking changes, at least in some cases we've encountered. While I understand it's a bug fix and that aligning behavior for form-associated custom elements is the right direction, it may still have unexpected side effects for existing implementations.

That said, I agree with the direction, and really appreciate the time and effort you all put into this work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: formAssociated element should treat boolean "disabled" Prop differently
2 participants