public static final String CLASSNAME = "v-select-optiongroup";
public static final String CLASSNAME_OPTION = "v-select-option";
+ public static final String CLASSNAME_OPTION_SELECTED = "v-select-option-selected";
private final Map<VCheckBox, JsonObject> optionsToItems;
widget.setValue(
item.getBoolean(ListingJsonConstants.JSONKEY_ITEM_SELECTED));
setOptionEnabled(widget, item);
+ widget.setStyleName(CLASSNAME_OPTION_SELECTED, widget.getValue());
if (requireInitialization) {
widget.addStyleName(CLASSNAME_OPTION);
import com.vaadin.shared.Registration;
import com.vaadin.shared.data.DataCommunicatorConstants;
import com.vaadin.shared.ui.ListingJsonConstants;
-
import elemental.json.JsonObject;
/**
public static final String CLASSNAME = "v-select-optiongroup";
public static final String CLASSNAME_OPTION = "v-select-option";
+ public static final String CLASSNAME_OPTION_SELECTED = "v-select-option-selected";
private final Map<RadioButton, JsonObject> optionsToItems;
private final Map<String, RadioButton> keyToOptions;
}
button.setHTML(itemHtml);
- button.setValue(
- item.getBoolean(ListingJsonConstants.JSONKEY_ITEM_SELECTED));
boolean optionEnabled = !item
.getBoolean(ListingJsonConstants.JSONKEY_ITEM_DISABLED);
boolean enabled = optionEnabled && !isReadonly() && isEnabled();
// #9258 apply the v-disabled class when disabled for UX
button.setStyleName(StyleConstants.DISABLED,
!isEnabled() || !optionEnabled);
+ updateItemSelection(button, item.getBoolean(ListingJsonConstants.JSONKEY_ITEM_SELECTED));
String key = item.getString(DataCommunicatorConstants.KEY);
}
public void selectItemKey(String selectedItemKey) {
+ // At most one item could be selected so reset all radio buttons
+ // before applying current selection
+ keyToOptions.values().forEach(button -> updateItemSelection(button, false));
if (selectedItemKey != null) {
RadioButton radioButton = keyToOptions.get(selectedItemKey);
if (radioButton != null) { // Items might not be loaded yet
- radioButton.setValue(true);
+ updateItemSelection(radioButton, true);
}
- } else {
- keyToOptions.values().forEach(button -> button.setValue(false));
}
}
+
+ protected void updateItemSelection(RadioButton radioButton, boolean value) {
+ radioButton.setValue(value);
+ radioButton.setStyleName(CLASSNAME_OPTION_SELECTED, value);
+ }
}
[classname]#CheckBox# component, and each radio button the
[literal]#++v-radiobutton++# style. Both the radio buttons and check boxes will
also have the [literal]#++v-select-option++# style that allows styling
-regardless of the option type. Disabled items have additionally the
+regardless of the option type and additionally [literal]#++v-select-option-selected++#
+when the item is selected. Disabled items have additionally the
[literal]#++v-disabled++# style.
verifyCheckboxDisabledClassNames(className, true);
}
+ @Test // #3387
+ public void shouldApplySelectedClassToSelectedItems() {
+ openTestURL("theme=valo");
+ selectMenuPath("Component", "Selection", "Toggle Item 5");
+
+ String className = getSelect().getOptionElements().get(5).getAttribute("className");
+ assertTrue("No v-select-option-selected class, was " + className, className.contains("v-select-option-selected"));
+
+ selectMenuPath("Component", "Selection", "Toggle Item 5");
+ className = getSelect().getOptionElements().get(5).getAttribute("className");
+ assertFalse("Extra v-select-option-selected class, was " + className, className.contains("v-select-option-selected"));
+ }
// needed to make tooltips work in IE tests
@Override
protected boolean requireWindowFocusForIE() {
package com.vaadin.tests.components.radiobuttongroup;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.List;
verifyRadioButtonDisabledClassNames(className, true);
}
+ @Test // #3387
+ public void shouldApplySelectedClassToSelectedItems() {
+ openTestURL("theme=valo");
+ selectMenuPath("Component", "Selection", "Toggle Item 5");
+
+ String className = getSelect().findElements(By.tagName("span")).get(5).getAttribute("className");
+ assertTrue("No v-select-option-selected class, was " + className, className.contains("v-select-option-selected")
+ );
+
+ getSelect().selectByText("Item 5");
+ className = getSelect().findElements(By.tagName("span")).get(5).getAttribute("className");
+ assertTrue("No v-select-option-selected class, was " + className, className.contains("v-select-option-selected"));
+
+ getSelect().selectByText("Item 10");
+ List<WebElement> options = getSelect().findElements(By.tagName("span"));
+ className = options.get(5).getAttribute("className");
+ assertFalse("Extra v-select-option-selected class, was " + className, className.contains("v-select-option-selected"));
+ className = options.get(10).getAttribute("className");
+ assertTrue("No v-select-option-selected class, was " + className, className.contains("v-select-option-selected"));
+
+ selectMenuPath("Component", "Selection", "Toggle Item 10");
+ className = getSelect().findElements(By.tagName("span")).get(10).getAttribute("className");
+ assertFalse("Extra v-select-option-selected class, was " + className, className.contains("v-select-option-selected"));
+ }
+
+
@Test
public void itemIconGenerator() {
selectMenuPath("Component", "Item Icon Generator",