webcomponents / polyfills

Web Components Polyfills
BSD 3-Clause "New" or "Revised" License
1.13k stars 166 forks source link

Scoped registry breaks formAssociated elements #481

Closed calebdwilliams closed 2 years ago

calebdwilliams commented 2 years ago

Description

Using the scoped elements registry breaks formAssociated components, somehow any formAssociated getter doesn't get set on the elements.

Example

You can find a reproduction on this StackBlitz demo.

Steps to reproduce

import '@webcomponents/scoped-custom-element-registry';

class Whatever extends HTMLElement {
  static get formAssociated() {
    return true;
  }

  internals = this.attachInternals();

  connectedCallback() {
    this.internals.setFormValue('foo');
  }
}

customElements.define('what-ev', Whatever);

document.getElementById('form').addEventListener('submit', (event) => {
  event.preventDefault();
  console.log(new FormData(event.target).get('whatever'));
});

const wrapper = document.createElement('div');
wrapper.innerHTML = `<form>
  <what-ev></what-ev>
</form>`;

/**
 * The above throws the following error
 * preview-a214a06f7a20.js:2 DOMException: Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element.
 */

Expected behavior

Form associated behavi

Actual behavior

Version

0.0.3

Browsers affected

calebdwilliams commented 2 years ago

This is fixed in version 0.0.4. Thanks all!