aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VNativeSelect.java24
-rw-r--r--server/src/main/java/com/vaadin/ui/NativeSelect.java29
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/nativeselect/NativeSelectState.java4
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelects.java19
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectVisibleItemCountTest.java42
5 files changed, 118 insertions, 0 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VNativeSelect.java b/client/src/main/java/com/vaadin/client/ui/VNativeSelect.java
index d838d9b3dd..80fc27ab98 100644
--- a/client/src/main/java/com/vaadin/client/ui/VNativeSelect.java
+++ b/client/src/main/java/com/vaadin/client/ui/VNativeSelect.java
@@ -110,4 +110,28 @@ public class VNativeSelect extends FocusableFlowPanelComposite
}
super.setHeight(height);
}
+
+ /**
+ * Sets the number of items that are visible. If only one item is visible,
+ * then the box will be displayed as a drop-down list (the default).
+ *
+ * @since
+ * @param visibleItemCount
+ * the visible item count
+ */
+ public void setVisibleItemCount(int visibleItemCount) {
+ getListBox().setVisibleItemCount(visibleItemCount);
+ }
+
+ /**
+ * Gets the number of items that are visible. If only one item is visible,
+ * then the box will be displayed as a drop-down list.
+ *
+ * @since
+ * @return the visible item count
+ */
+ public int getVisibleItemCount() {
+ return getListBox().getVisibleItemCount();
+ }
+
}
diff --git a/server/src/main/java/com/vaadin/ui/NativeSelect.java b/server/src/main/java/com/vaadin/ui/NativeSelect.java
index 4d08aacd12..a0d5741262 100644
--- a/server/src/main/java/com/vaadin/ui/NativeSelect.java
+++ b/server/src/main/java/com/vaadin/ui/NativeSelect.java
@@ -203,4 +203,33 @@ public class NativeSelect<T> extends AbstractSingleSelect<T>
Objects.nonNull(caption);
getState().emptySelectionCaption = caption;
}
+
+ /**
+ * Sets the number of items that are visible. If only one item is visible,
+ * then the box will be displayed as a drop-down list (the default).
+ *
+ * @since
+ * @param visibleItemCount
+ * the visible item count
+ * @throws IllegalArgumentException
+ * if the value is smaller than one
+ */
+ public void setVisibleItemCount(int visibleItemCount) {
+ if (visibleItemCount < 1) {
+ throw new IllegalArgumentException(
+ "There must be at least one item visible");
+ }
+ getState().visibleItemCount = visibleItemCount;
+ }
+
+ /**
+ * Gets the number of items that are visible. If only one item is visible,
+ * then the box will be displayed as a drop-down list.
+ *
+ * @since
+ * @return the visible item count
+ */
+ public int getVisibleItemCount() {
+ return getState(false).visibleItemCount;
+ }
}
diff --git a/shared/src/main/java/com/vaadin/shared/ui/nativeselect/NativeSelectState.java b/shared/src/main/java/com/vaadin/shared/ui/nativeselect/NativeSelectState.java
index c33cc66f82..86872298e6 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/nativeselect/NativeSelectState.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/nativeselect/NativeSelectState.java
@@ -15,6 +15,7 @@
*/
package com.vaadin.shared.ui.nativeselect;
+import com.vaadin.shared.annotations.DelegateToWidget;
import com.vaadin.shared.ui.AbstractSingleSelectState;
/**
@@ -43,6 +44,9 @@ public class NativeSelectState extends AbstractSingleSelectState {
*/
public String emptySelectionCaption = "";
+ @DelegateToWidget
+ public int visibleItemCount = 1;
+
{
primaryStyleName = STYLE_NAME;
}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelects.java b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelects.java
index 34b78089bb..2f67f78304 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelects.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelects.java
@@ -1,5 +1,7 @@
package com.vaadin.tests.components.nativeselect;
+import java.util.LinkedHashMap;
+
import com.vaadin.tests.components.abstractlisting.AbstractSingleSelectTestUI;
import com.vaadin.ui.NativeSelect;
@@ -18,4 +20,21 @@ public class NativeSelects
component.setEmptySelectionAllowed(false);
return component;
}
+
+ @Override
+ protected void createActions() {
+ super.createActions();
+ LinkedHashMap<String, Integer> options = new LinkedHashMap<>();
+ options.put("1", 1);
+ options.put("2", 2);
+ options.put("5", 5);
+ createSelectAction("Visible item count", CATEGORY_SIZE, options, "1",
+ new Command<NativeSelect<Object>, Integer>() {
+ @Override
+ public void execute(NativeSelect<Object> c, Integer value,
+ Object data) {
+ c.setVisibleItemCount(value);
+ }
+ });
+ }
}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectVisibleItemCountTest.java b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectVisibleItemCountTest.java
new file mode 100644
index 0000000000..95af50e55d
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectVisibleItemCountTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.nativeselect;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.NativeSelectElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class NativeSelectVisibleItemCountTest extends SingleBrowserTest {
+
+ @Test
+ public void changeItemCount() {
+ openTestURL();
+ WebElement select = $(NativeSelectElement.class).first()
+ .findElement(By.xpath("select"));
+ Assert.assertEquals("1", select.getAttribute("size"));
+ selectMenuPath("Component", "Size", "Visible item count", "5");
+ Assert.assertEquals("5", select.getAttribute("size"));
+ }
+
+ @Override
+ protected Class<?> getUIClass() {
+ return NativeSelects.class;
+ }
+}