-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Support for two-way binding on custom elements #892
Comments
Wrote a simple example using a web component library that shows this https://svelte.dev/repl/bc48abd5c41d4dee833e5757745cf57f?version=3.4.4 Seems like this is blocked in the compiler. this.bindings.forEach(binding => {
const { name } = binding;
if (name === 'value') {
if (this.name !== 'input' &&
this.name !== 'textarea' &&
this.name !== 'select') {
component.error(binding, {
code: `invalid-binding`,
message: `'value' is not a valid binding on <${this.name}> elements`
});
} |
@nsaunders I don't know if this is what you looking for, I try to add Modal.svelte
Parent.svelte
|
If someones comes across this is search of a clearer answer, If you want to bind to a "regular" html input, you can use the usual If you want to bind to a custom element you created:
then in your custom component:
Cheers, |
@sudomaxime any hint while this is not working for ui5-input element? The propname in ui5-input is "value" https://codesandbox.io/s/divine-architecture-3qvlc?file=/App.svelte |
It seems the method mentioned by @sudomaxime is not working when HelloWorld.svelte (child) <script>
import Hello from './components/Hello'
import World from './components/World'
export let value;
</script>
<svelte:options tag={'x-app-helloworld'}/>
<input type="text" bind:value={value} >
<input>
<x-app-hello />
<x-app-world /> App.svslte(parent)
Then the parent will show an error: How can I solve this? |
@MAXI0008 I opened another issue... #4838 |
Same issue with ionic ion-input element. A webcomponent too. |
Hi @antony - just curious if it is possible to reopen this one? You closed it maybe because of @sudomaxime comment, but that solution only works if you control the webcomponent As you can see per later comments and still there - looking at my comment - if you don't control the webcomponent you can still not bind:value to get the binding to the elements value property. Or do we need a workaround like mentioned here - https://css-tricks.com/using-custom-elements-in-svelte/ Wrapping the custom element in another custom element and then making the property reflective or something like that? Or even use:action for it? |
Custom Elements (as in Web Components) cannot currently take advantage of two-way binding syntax.
For example, instead of this...
...I have to do this...
I think this is kind of a bummer. :-(
The text was updated successfully, but these errors were encountered: