diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2018-03-19 18:50:17 +0200 |
---|---|---|
committer | Ilia Motornyi <elmot@vaadin.com> | 2018-03-19 18:50:17 +0200 |
commit | 81f81fa3c41f1fc97a14b7f8d91cf6ea29af572b (patch) | |
tree | 5347a180628cf419250e32530a966f5366dddd8e /client | |
parent | 649f2f3eeae246e8f57e433c5fd3dcc8fe488d6c (diff) | |
download | vaadin-framework-81f81fa3c41f1fc97a14b7f8d91cf6ea29af572b.tar.gz vaadin-framework-81f81fa3c41f1fc97a14b7f8d91cf6ea29af572b.zip |
Fix initially disabled items in RadioButtonGroup (#10719)
Diffstat (limited to 'client')
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/VRadioButtonGroup.java | 42 | ||||
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java | 1 |
2 files changed, 26 insertions, 17 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VRadioButtonGroup.java b/client/src/main/java/com/vaadin/client/ui/VRadioButtonGroup.java index 479e41a9b5..30335fd975 100644 --- a/client/src/main/java/com/vaadin/client/ui/VRadioButtonGroup.java +++ b/client/src/main/java/com/vaadin/client/ui/VRadioButtonGroup.java @@ -139,6 +139,13 @@ public class VRadioButtonGroup extends FocusableFlowPanelComposite private void updateItem(RadioButton button, JsonObject item, boolean requireInitialization) { + if (requireInitialization) { + getWidget().add(button); + button.setStyleName("v-radiobutton"); + button.addStyleName(CLASSNAME_OPTION); + button.addClickHandler(this); + } + String itemHtml = item .getString(ListingJsonConstants.JSONKEY_ITEM_VALUE); if (!isHtmlContentAllowed()) { @@ -154,22 +161,12 @@ public class VRadioButtonGroup extends FocusableFlowPanelComposite button.setHTML(itemHtml); boolean optionEnabled = !item .getBoolean(ListingJsonConstants.JSONKEY_ITEM_DISABLED); - boolean enabled = optionEnabled && !isReadonly() && isEnabled(); - button.setEnabled(enabled); - // #9258 apply the v-disabled class when disabled for UX - button.setStyleName(StyleConstants.DISABLED, - !isEnabled() || !optionEnabled); + updateItemEnabled(button, optionEnabled); updateItemSelection(button, item.getBoolean(ListingJsonConstants.JSONKEY_ITEM_SELECTED)); String key = item.getString(DataCommunicatorConstants.KEY); - if (requireInitialization) { - getWidget().add(button); - button.setStyleName("v-radiobutton"); - button.addStyleName(CLASSNAME_OPTION); - button.addClickHandler(this); - } optionsToItems.put(button, item); keyToOptions.put(key, button); } @@ -205,7 +202,6 @@ public class VRadioButtonGroup extends FocusableFlowPanelComposite } protected void updateEnabledState() { - boolean radioButtonEnabled = isEnabled() && !isReadonly(); // sets options enabled according to the widget's enabled, // readonly and each options own enabled for (Map.Entry<RadioButton, JsonObject> entry : optionsToItems @@ -214,10 +210,7 @@ public class VRadioButtonGroup extends FocusableFlowPanelComposite JsonObject value = entry.getValue(); boolean optionEnabled = !value .getBoolean(ListingJsonConstants.JSONKEY_ITEM_DISABLED); - radioButton.setEnabled(radioButtonEnabled && optionEnabled); - // #9258 apply the v-disabled class when disabled for UX - radioButton.setStyleName(StyleConstants.DISABLED, - !isEnabled() || !optionEnabled); + updateItemEnabled(radioButton, optionEnabled); } } @@ -305,6 +298,23 @@ public class VRadioButtonGroup extends FocusableFlowPanelComposite protected void updateItemSelection(RadioButton radioButton, boolean value) { radioButton.setValue(value); radioButton.setStyleName(CLASSNAME_OPTION_SELECTED, value); + } + /** + * Updates the enabled state of a radio button. + * + * @param radioButton + * the radio button to update + * @param value + * {@code true} if enabled; {@code false} if not + * + * @since + */ + protected void updateItemEnabled(RadioButton radioButton, boolean value) { + boolean enabled = value && !isReadonly() && isEnabled(); + radioButton.setEnabled(enabled); + // #9258 apply the v-disabled class when disabled for UX + boolean hasDisabledStyle = !isEnabled() || !value; + radioButton.setStyleName(StyleConstants.DISABLED, hasDisabledStyle); } } diff --git a/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java b/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java index ca008d0087..0af2d1f487 100644 --- a/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java @@ -85,7 +85,6 @@ public class RadioButtonGroupConnector } @OnStateChange("readOnly") - @SuppressWarnings("deprecation") void updateWidgetReadOnly() { getWidget().setEnabled(isEnabled() && !isReadOnly()); } |