-
Notifications
You must be signed in to change notification settings - Fork 10
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
RBG inside polymer template inside a dialog resets the value unexpectedly. #166
Comments
Thanks for the code example. I wasn't able to reproduce this issue in Chrome, see the GIF below: It worked the same in Firefox and Safari. |
My image: Technically, it's not about this bug. This is just a demonstration that something is broken on the client side. |
Could you please check your Chrome version? Also, did you check if it also happens in Firefox or Safari for you? |
No, I have not checked neither Firefox nor Safari: it's enough that it can be reproduced in Chrome. Have you checked the original bug ? Were you able to reproduce it ? |
Thanks. I have the same version, so no idea what's going on here. Will check the original bug. |
Regarding the original issue, did some debugging with the project provided by the user and got this: 1st row dialog open
2nd row dialog open
SummaryWe are talking about different Especially, the |
Wasn't able to reproduce the issue with the example from Denis. I have done some investigation as well. I have created a minimal reproducible example for the original issue created by user. Can be tested on MainView.java import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.html.NativeButton;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.select.Select;
import com.vaadin.flow.router.Route;
@Route("test-issue")
public class MainView extends VerticalLayout {
private final MainForm mainForm;
public MainView() {
this.mainForm = new MainForm();
Select<String> select = new Select<>();
select.setItems("A", "B", "C");
NativeButton bt = new NativeButton("Open Dialog", e -> openDialog(select.getValue()));
add(select, bt);
}
private void openDialog(String val) {
mainForm.setRBGValue(val);
new Dialog(mainForm).open();
}
} MainForm.java import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.polymertemplate.Id;
import com.vaadin.flow.component.polymertemplate.PolymerTemplate;
import com.vaadin.flow.component.radiobutton.RadioButtonGroup;
import com.vaadin.flow.templatemodel.TemplateModel;
@JsModule("./src/main-form.js")
@Tag("main-form")
public class MainForm extends PolymerTemplate<TemplateModel> {
@Id("kind")
RadioButtonGroup<String> kind;
public MainForm() {
kind.setItems("A", "B", "C");
}
public void setRBGValue(String val) {
// Workaround here
// kind.setItems("A", "B", "C");
kind.setValue(val);
}
} frontend/src/main-form.js import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import '@vaadin/vaadin-radio-button/src/vaadin-radio-group.js';
class MainForm extends PolymerElement {
//language=html
static get template() {
return html`
<vaadin-radio-group id="kind"></vaadin-radio-group>
`;
}
static get is() {
return 'main-form';
}
}
customElements.define(MainForm.is, MainForm); Steps to reproduce
Explanation Workaround Fix |
This seems to happen because RBG automatically adds RadioButtons inside of itself here. Now, if the RBG's value gets changed (setValue) while the component isn't in the DOM, the internal RB's remain unchanged. And once they're added back to DOM, Flow synchronizes the old RB values which causes the RBG to revert back to the old value. To fix this, you can for example override @Override
public void setValue(T value) {
super.setValue(value);
getRadioButtons().forEach(rb -> rb.setChecked(rb.getItem().equals(value)));
} ...but please take a closer look if there's a cleaner fix available (maybe just calling Note that Dialog isn't related to the issue. You can also just |
Web-component: radio-button Fixes: vaadin/vaadin-radio-button#166 Details: RBG automatically adds RadioButtons inside of itself. If the RBG's value gets changed (setValue) while the component isn't in the DOM, the internal RB's remain unchanged. And once they're added back to DOM, Flow synchronizes the old RB values which causes the RBG to revert back to the old value. In order to fix it buttons will be reset on detach.
Web-component: radio-button Fixes: vaadin/vaadin-radio-button#166 Details: RBG automatically adds RadioButtons inside of itself. If the RBG's value gets changed (setValue) while the component isn't in the DOM, the internal RB's remain unchanged. And once they're added back to DOM, Flow synchronizes the old RB values which causes the RBG to revert back to the old value. In order to fix it buttons will be reset on detach.
Web-component: radio-button Fixes: vaadin/vaadin-radio-button#166 Details: RBG automatically adds RadioButtons inside of itself. If the RBG's value gets changed (setValue) while the component isn't in the DOM, the internal RB's remain unchanged. And once they're added back to DOM, Flow synchronizes the old RB values which causes the RBG to revert back to the old value. In order to fix it buttons will be reset on detach.
Web-component: radio-button Fixes: vaadin/vaadin-radio-button#166 Details: RBG automatically adds RadioButtons inside of itself. If the RBG's value gets changed (setValue) while the component isn't in the DOM, the internal RB's remain unchanged. And once they're added back to DOM, Flow synchronizes the old RB values which causes the RBG to revert back to the old value. In order to fix it buttons will be reset on detach. * Override setValue * Add test for attach-detach
Web-component: radio-button Fixes: vaadin/vaadin-radio-button#166 Details: RBG automatically adds RadioButtons inside of itself. If the RBG's value gets changed (setValue) while the component isn't in the DOM, the internal RB's remain unchanged. And once they're added back to DOM, Flow synchronizes the old RB values which causes the RBG to revert back to the old value. In order to fix it buttons will be reset on detach. * Override setValue * Add test for attach-detach
Web-component: radio-button Fixes: vaadin/vaadin-radio-button#166 Details: RBG automatically adds RadioButtons inside of itself. If the RBG's value gets changed (setValue) while the component isn't in the DOM, the internal RB's remain unchanged. And once they're added back to DOM, Flow synchronizes the old RB values which causes the RBG to revert back to the old value. In order to fix it buttons will be reset on detach. * Override setValue * Add test for attach-detach
Web-component: radio-button Fixes: vaadin/vaadin-radio-button#166 Details: RBG automatically adds RadioButtons inside of itself. If the RBG's value gets changed (setValue) while the component isn't in the DOM, the internal RB's remain unchanged. And once they're added back to DOM, Flow synchronizes the old RB values which causes the RBG to revert back to the old value. In order to fix it buttons will be reset on detach. * Override setValue * Add test for attach-detach
* fix: override setValue to set proper value when detached (#275) Web-component: radio-button Fixes: vaadin/vaadin-radio-button#166 Details: RBG automatically adds RadioButtons inside of itself. If the RBG's value gets changed (setValue) while the component isn't in the DOM, the internal RB's remain unchanged. And once they're added back to DOM, Flow synchronizes the old RB values which causes the RBG to revert back to the old value. In order to fix it buttons will be reset on detach. * Override setValue * Add test for attach-detach * Update setItems Co-authored-by: Yuriy Yevstihnyeyev <yuriy@vaadin.com>
* fix: override setValue to set proper value when detached (#275) Web-component: radio-button Fixes: vaadin/vaadin-radio-button#166 Details: RBG automatically adds RadioButtons inside of itself. If the RBG's value gets changed (setValue) while the component isn't in the DOM, the internal RB's remain unchanged. And once they're added back to DOM, Flow synchronizes the old RB values which causes the RBG to revert back to the old value. In order to fix it buttons will be reset on detach. * Override setValue * Add test for attach-detach * Update setItems Co-authored-by: Yuriy Yevstihnyeyev <yuriy@vaadin.com>
* fix: override setValue to set proper value when detached (#275) Web-component: radio-button Fixes: vaadin/vaadin-radio-button#166 Details: RBG automatically adds RadioButtons inside of itself. If the RBG's value gets changed (setValue) while the component isn't in the DOM, the internal RB's remain unchanged. And once they're added back to DOM, Flow synchronizes the old RB values which causes the RBG to revert back to the old value. In order to fix it buttons will be reset on detach. * Override setValue * Add test for attach-detach * Update setItems Co-authored-by: Yuriy Yevstihnyeyev <yuriy@vaadin.com>
Sorry that I'm using Java example but I don't know how make non Java example easily.
Java based example is used only for setup components. The bug is pure client side.
The original ticket is vaadin/vaadin-radio-button-flow#162
Steps to reproduce:
Use skeleton starter
https://github.com/vaadin/skeleton-starter-flow
Replace
MainView
with the content:Use this template for
main-form.js
:"$0.value"
should be"2"
, set it to"1"
:$0.value=1
.So some "focus" event or something trigger value change back unexpectedly.
This is caused by
vaadin-radio-button-group
web component on the client side since no any server side events happen on move.The text was updated successfully, but these errors were encountered: