Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a form in shadow DOM to be the form owner of light DOM fields #10220

Open
jakearchibald opened this issue Mar 22, 2024 · 7 comments
Open
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: custom elements Relates to custom elements (as defined in DOM and HTML) topic: forms topic: shadow Relates to shadow trees (as defined in DOM)

Comments

@jakearchibald
Copy link
Contributor

What problem are you trying to solve?

I want to create a custom element, <ui-form>, which has or wraps form functionality.

What solutions exist today?

<form is="my-custom-thing">, but WebKit opposes this.

How would you solve it?

Assuming that WebKit will not change their position:

My <ui-form> could create a shadow root which contains <form><slot></slot></form>.

However, at present (although it isn't clear from the algorithm), shadow boundaries are not crossed when associating fields with forms.

Instead, the algorithm could be updated to cross-shadow boundaries. For compatibility, the form must opt-in to being considered when crossing shadow boundaries: <form allowcrossshadowboundarypleasethankyou>. There may be better names.

Anything else?

No response

@jakearchibald jakearchibald added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest labels Mar 22, 2024
@jakearchibald
Copy link
Contributor Author

An alternative would be something like:

class MyCustomElement {
  static form = true;
}

Similar to formAssociated. Then elementInternals could be used to configure form behaviour.

@annevk annevk added topic: shadow Relates to shadow trees (as defined in DOM) topic: custom elements Relates to custom elements (as defined in DOM and HTML) topic: forms labels Mar 22, 2024
@developit
Copy link

+1 to this - it seems like most of the UI toolkits built on Custom Elements have had to work around this, often by "patching" fields within shadow boundaries into FormData via the formdata event - tricky to do correctly for arbitrary input types (esp files).

@smaug----
Copy link

So how would the .form getter work for the slotted elements?

@keithamus
Copy link
Contributor

I wonder if Custom Attributes (WICG/webcomponents#1029) would solve for your usecase?

@jakearchibald
Copy link
Contributor Author

@keithamus I don't think so. This would be a custom element with potential UI in a shadow root.

@jakearchibald
Copy link
Contributor Author

@smaug----

So how would the .form getter work for the slotted elements?

Good point. I guess that answer is much easier in the alternative idea #10220 (comment), since it would just be the custom element.

@KonnorRogers
Copy link

I know this is whatwg/html, but this issue around elements which have ElementInternals being able to register as a "submit button" seems very similar.

WICG/webcomponents#814

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: custom elements Relates to custom elements (as defined in DOM and HTML) topic: forms topic: shadow Relates to shadow trees (as defined in DOM)
Development

No branches or pull requests

7 participants
@jakearchibald @developit @keithamus @annevk @smaug---- @KonnorRogers and others