summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-04-13 10:52:19 +0300
committerIlia Motornyi <elmot@vaadin.com>2017-04-13 09:52:19 +0200
commit22c39d36f81a6d37f729d67135487ef10cb8dc5a (patch)
treef4697f175a44753e59ae47be00c3f72cd3bf21c6
parent71e4d797fe6a3629f9e489b06e2566e139577bfd (diff)
downloadvaadin-framework-22c39d36f81a6d37f729d67135487ef10cb8dc5a.tar.gz
vaadin-framework-22c39d36f81a6d37f729d67135487ef10cb8dc5a.zip
Correctly set ListSelect style names
Fixes #8901
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VListSelect.java29
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/listselect/ListSelectState.java3
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/listselect/ListSelectStyleNames.java55
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/listselect/ListSelectStyleNamesTest.java92
4 files changed, 159 insertions, 20 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VListSelect.java b/client/src/main/java/com/vaadin/client/ui/VListSelect.java
index 9ce897de0e..b00a9513f1 100644
--- a/client/src/main/java/com/vaadin/client/ui/VListSelect.java
+++ b/client/src/main/java/com/vaadin/client/ui/VListSelect.java
@@ -30,6 +30,7 @@ import com.vaadin.client.FastStringSet;
import com.vaadin.client.Focusable;
import com.vaadin.client.connectors.AbstractMultiSelectConnector.MultiSelectWidget;
import com.vaadin.shared.Registration;
+import com.vaadin.shared.ui.listselect.ListSelectState;
import elemental.json.JsonObject;
@@ -57,6 +58,7 @@ public class VListSelect extends Composite
*/
public VListSelect() {
container = new FlowPanel();
+
initWidget(container);
select = new ListBox();
@@ -71,6 +73,13 @@ public class VListSelect extends Composite
container.add(select);
updateEnabledState();
+ setStylePrimaryName(ListSelectState.PRIMARY_STYLENAME);
+ }
+
+ @Override
+ public void setStylePrimaryName(String style) {
+ super.setStylePrimaryName(style);
+ select.setStyleName(style + "-select");
}
/**
@@ -105,24 +114,6 @@ public class VListSelect extends Composite
}
@Override
- public void setStyleName(String style) {
- super.setStyleName(style);
- updateStyleNames();
- }
-
- @Override
- public void setStylePrimaryName(String style) {
- super.setStylePrimaryName(style);
- updateStyleNames();
- }
-
- /** Update the style names for container & select. */
- protected void updateStyleNames() {
- container.setStyleName(getStylePrimaryName());
- select.setStyleName(getStylePrimaryName() + "-select");
- }
-
- @Override
public void setItems(List<JsonObject> items) {
selectedItemKeys = FastStringSet.create();
for (int i = 0; i < items.size(); i++) {
@@ -163,7 +154,7 @@ public class VListSelect extends Composite
return selectedItemKeys;
}
- private void selectionEvent(Object source){
+ private void selectionEvent(Object source) {
if (source == select) {
// selection can change by adding and at the same time removing
// previous keys, or by just adding (e.g. when modifier keys are
diff --git a/shared/src/main/java/com/vaadin/shared/ui/listselect/ListSelectState.java b/shared/src/main/java/com/vaadin/shared/ui/listselect/ListSelectState.java
index a749786ae3..aae8f428da 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/listselect/ListSelectState.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/listselect/ListSelectState.java
@@ -25,8 +25,9 @@ import com.vaadin.shared.ui.abstractmultiselect.AbstractMultiSelectState;
* @since 8.0
*/
public class ListSelectState extends AbstractMultiSelectState {
+ public static final String PRIMARY_STYLENAME = "v-select";
{
- primaryStyleName = "v-select";
+ primaryStyleName = PRIMARY_STYLENAME;
}
@DelegateToWidget
public int rows;
diff --git a/uitest/src/main/java/com/vaadin/tests/components/listselect/ListSelectStyleNames.java b/uitest/src/main/java/com/vaadin/tests/components/listselect/ListSelectStyleNames.java
new file mode 100644
index 0000000000..9e9ee78dd4
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/listselect/ListSelectStyleNames.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.listselect;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.ListSelect;
+import com.vaadin.ui.NativeSelect;
+
+@Widgetset("com.vaadin.DefaultWidgetSet")
+public class ListSelectStyleNames extends AbstractTestUIWithLog {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ ListSelect<String> testselect = new ListSelect<>();
+ testselect.setItems("abc", "def", "ghi");
+ testselect.addStyleName("custominitial");
+ addComponent(testselect);
+
+ NativeSelect<String> nativeSelect = new NativeSelect<>();
+ nativeSelect.setItems("abc", "def", "ghi");
+ nativeSelect.addStyleName("custominitial");
+ addComponent(nativeSelect);
+
+ Button button = new Button("Add style 'new'", e -> {
+ testselect.addStyleName("new");
+ nativeSelect.addStyleName("new");
+ });
+ button.setId("add");
+ addComponent(button);
+
+ button = new Button("Change primary style to 'newprimary'", e -> {
+ testselect.setPrimaryStyleName("newprimary");
+ nativeSelect.setPrimaryStyleName("newprimary");
+ });
+ button.setId("changeprimary");
+ addComponent(button);
+ }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/listselect/ListSelectStyleNamesTest.java b/uitest/src/test/java/com/vaadin/tests/components/listselect/ListSelectStyleNamesTest.java
new file mode 100644
index 0000000000..7e032ba94b
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/listselect/ListSelectStyleNamesTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.listselect;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+
+import com.vaadin.testbench.TestBenchElement;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.ListSelectElement;
+import com.vaadin.testbench.elements.NativeSelectElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class ListSelectStyleNamesTest extends SingleBrowserTest {
+
+ private NativeSelectElement nativeSelect;
+ private TestBenchElement nativeSelectSelect;
+ private ListSelectElement listSelect;
+ private TestBenchElement listSelectSelect;
+
+ @Override
+ public void setup() throws Exception {
+ super.setup();
+ openTestURL();
+ nativeSelect = $(NativeSelectElement.class).first();
+ nativeSelectSelect = (TestBenchElement) nativeSelect
+ .findElement(By.xpath("select"));
+
+ listSelect = $(ListSelectElement.class).first();
+ listSelectSelect = (TestBenchElement) listSelect
+ .findElement(By.xpath("select"));
+
+ }
+
+ @Test
+ public void correctInitialStyleNames() {
+ assertStyleNames(nativeSelect, "v-select", "v-widget", "custominitial",
+ "v-select-custominitial");
+ assertStyleNames(nativeSelectSelect, "v-select-select");
+ assertStyleNames(listSelect, "v-select", "v-widget", "custominitial",
+ "v-select-custominitial");
+ assertStyleNames(listSelectSelect, "v-select-select");
+ }
+
+ @Test
+ public void addStyleName() {
+ $(ButtonElement.class).id("add").click();
+ assertStyleNames(nativeSelect, "v-select", "v-widget", "custominitial",
+ "v-select-custominitial", "new", "v-select-new");
+ assertStyleNames(nativeSelectSelect, "v-select-select");
+ assertStyleNames(listSelect, "v-select", "v-widget", "custominitial",
+ "v-select-custominitial", "new", "v-select-new");
+ assertStyleNames(listSelectSelect, "v-select-select");
+ }
+
+ @Test
+ public void changePrimaryStyleName() {
+ $(ButtonElement.class).id("add").click();
+ $(ButtonElement.class).id("changeprimary").click();
+ assertStyleNames(nativeSelect, "newprimary", "v-widget",
+ "custominitial", "newprimary-custominitial", "new",
+ "newprimary-new");
+ assertStyleNames(nativeSelectSelect, "newprimary");
+ assertStyleNames(listSelect, "newprimary", "v-widget", "custominitial",
+ "newprimary-custominitial", "new", "newprimary-new");
+ assertStyleNames(listSelectSelect, "newprimary-select");
+
+ }
+
+ private void assertStyleNames(TestBenchElement element,
+ String... styleNames) {
+ Assert.assertEquals(new HashSet<>(Arrays.asList(styleNames)),
+ element.getClassNames());
+ }
+}