-
-
Notifications
You must be signed in to change notification settings - Fork 261
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
Checkbox with 1-way binding and change
results in a weird state
#977
Comments
I'm unable to repro when putting the code in the Svelte REPL: https://svelte.dev/repl/6f48c872218b49d89ab115e8e9b09e97?version=3.44.3 It's using the latest Am I missing anything? |
It took me some trials to figure out the combination of the versions that fixed the error. With the following patch (edited for brevity) the issue disappeared, meaning it was somewhere in the combination of an older diff --git a/package.json b/package.json
index f5a49d64..866d99af 100644
--- a/clients/crm/package.json
+++ b/clients/crm/package.json
@@ -21,8 +21,9 @@
- "carbon-components": "^10.29.0",
- "carbon-components-svelte": "^0.44.5",
+ "carbon-components": "^10.50.0",
+ "carbon-components-svelte": "^0.51.1",
+ "carbon-icons-svelte": "^10.44.3", |
Curious – why do you have |
The issue is still present after all. Visually everything seems to match, but the internal state of the |
@metonym Any thoughts on this? Can you confirm the bug? Happy to provide a PR if so. |
@koffeinfrei Just throwing it out there that I'm not sure if "on:change" should even be forwarded. "on:check" should be the event to listen for [1]. Regardless, I'm happy to review a PR that would fix the behavior. [1] |
Do you mean because
The issue with that event is that it doesn't include the field's name, only the
👉 #1013 |
Fixed in v0.52.0 Thanks for getting to the bottom of this! |
Just to close the loop on the discussion:
This is my personal opinion: my understanding of the "Svelte way" is to be as concise as possible. This means using two-way binding instead of relying on dispatched events to manage state (like in React). However, I understand that it may be simpler sometimes to just listen to an event when you do not need to manage state (like
True. |
Thanks! That was fast! 🙌 |
👍 |
When using a checkbox with 1-way binding and the
change
event the state of the checkbox doesn't match the UIThe following example visualizes the issue when clicking the checkbox
checkbox.mp4
The problem seems to be in the order of the
on:change
declarations in theCheckbox
component.Here is the diff that solved my problem:
I used patch-package to patch
carbon-components-svelte@0.44.7
for the project I'm working on.This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: