lwc icon indicating copy to clipboard operation
lwc copied to clipboard

`UpgradableConstructor` should only apply `formAssociated` on-demand and throw in case of conflicts

Open jmsjtu opened this issue 1 year ago • 2 comments

Description

The introduction of formAssociated on the UpgradeableConstructor in #3695 has introduced unintended observable changes to custom elements.

This is causing the browser to identify LWC components as form-associated elements. This is an issue for components that contain form inputs, as secondary clicks for labels are now dispatched on the label-associated host element instead of any internal form inputs (e.g., input).

A repro can be found here.

Click the label element ("awesome checkbox" text) to observe the differences in behavior when formAssociated is true vs false.

The checkbox will check when the label is clicked with formAssociated=false but will not when formAssociated=true.

jmsjtu avatar Feb 07 '24 19:02 jmsjtu

This issue has been linked to a new work item: W-15001648

git2gus[bot] avatar Feb 09 '24 01:02 git2gus[bot]

New design, which aligns with LWS:

  • The first definition of a component (e.g. <x-foo>) gets to set the class's formAssociated-ness to either false or true.
  • The following definitions are subject to a check:
    • If there is an existing definition for the tag name (e.g. <x-foo>) and the existing definition's formAssociated value does not equal the new definition's formAssociated value, throw an exception with clear explanation.
    • E.g.: <x-foo> was already registered with formAssociated=true. It cannot be re-registered with formAssociated=false. Please rename your component to have a different name than <x-foo> (link to lwc.dev documentation)

nolanlawson avatar Feb 15 '24 17:02 nolanlawson