diff options
author | ZheSun88 <zhe@vaadin.com> | 2018-11-13 15:50:02 +0200 |
---|---|---|
committer | Sun Zhe <31067185+ZheSun88@users.noreply.github.com> | 2018-11-13 16:40:32 +0200 |
commit | 5f4c9ea49de41dc9f1205a5af5bc925b86346809 (patch) | |
tree | ee9176ec1c9e0af087a64bc022e080ff43b4e8d4 | |
parent | 2bfc76f63d4835237e29880d49b59f0a0c8e0c5b (diff) | |
download | vaadin-framework-5f4c9ea49de41dc9f1205a5af5bc925b86346809.tar.gz vaadin-framework-5f4c9ea49de41dc9f1205a5af5bc925b86346809.zip |
Revert "Display the caption of the Empty selection in NativeSelect (#11191)"
This reverts commit 77ab4c6da252566dbc7c05046c4488adeb7f970d.
5 files changed, 1 insertions, 127 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 f92aa05e42..f6980050b6 100644 --- a/client/src/main/java/com/vaadin/client/ui/VNativeSelect.java +++ b/client/src/main/java/com/vaadin/client/ui/VNativeSelect.java @@ -29,7 +29,6 @@ import com.vaadin.shared.ui.nativeselect.NativeSelectState; public class VNativeSelect extends FocusableFlowPanelComposite { private final ListBox listBox = new ListBox(); - private boolean emptySelectionAllowed = true; /** * Creates a new {@code VNativeSelect} instance. @@ -56,11 +55,7 @@ public class VNativeSelect extends FocusableFlowPanelComposite { */ public void setSelectedItem(String value) { if (value == null) { - if (emptySelectionAllowed) { - getListBox().setSelectedIndex(0); - } else { - getListBox().setSelectedIndex(-1); - } + getListBox().setSelectedIndex(-1); } else { for (int i = 0; i < getListBox().getItemCount(); i++) { if (Objects.equals(value, getListBox().getValue(i))) { @@ -137,23 +132,4 @@ public class VNativeSelect extends FocusableFlowPanelComposite { return getListBox().getVisibleItemCount(); } - /** - * Returns true if empty selection is allowed. - * - * @since - * @return empty selection is allowed - */ - public boolean isEmptySelectionAllowed() { - return emptySelectionAllowed; - } - - /** - * Sets true if empty selection is allowed. - * - * @since - * @param emptySelectionAllowed - */ - public void setEmptySelectionAllowed(boolean emptySelectionAllowed) { - this.emptySelectionAllowed = emptySelectionAllowed; - } } diff --git a/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java b/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java index 5f17ac4e64..44b6c3b831 100644 --- a/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java @@ -95,14 +95,10 @@ public class NativeSelectConnector ListBox listBox = getWidget().getListBox(); boolean hasEmptyItem = listBox.getItemCount() > 0 && listBox.getValue(0).isEmpty(); - getWidget().setEmptySelectionAllowed(getState().emptySelectionAllowed); if (hasEmptyItem && getState().emptySelectionAllowed) { listBox.setItemText(0, getState().emptySelectionCaption); } else if (hasEmptyItem && !getState().emptySelectionAllowed) { listBox.removeItem(0); - if (getWidget().getListBox().getSelectedIndex() == 0) { - getWidget().setSelectedItem(null); - } } else if (!hasEmptyItem && getState().emptySelectionAllowed) { listBox.insertItem(getState().emptySelectionCaption, 0); listBox.setValue(0, ""); diff --git a/uitest/src/main/java/com/vaadin/tests/components/abstractsingleselect/AbstractSingleSelection.java b/uitest/src/main/java/com/vaadin/tests/components/abstractsingleselect/AbstractSingleSelection.java index 44ea73dc88..fc10d13b53 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/abstractsingleselect/AbstractSingleSelection.java +++ b/uitest/src/main/java/com/vaadin/tests/components/abstractsingleselect/AbstractSingleSelection.java @@ -50,9 +50,6 @@ public class AbstractSingleSelection extends AbstractTestUI { .newInstance(); select.setItems("Foo", "Bar", "Baz", "Reset"); select.setSelectedItem("Bar"); - if (select instanceof NativeSelect) { - ((NativeSelect) select).setEmptySelectionAllowed(false); - } select.addValueChangeListener(event -> { if ("Reset".equals(event.getValue())) { diff --git a/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectSetNull.java b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectSetNull.java deleted file mode 100644 index fc6c0f2f6c..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectSetNull.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.vaadin.tests.components.nativeselect; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.NativeSelect; -import com.vaadin.ui.Button; - -public class NativeSelectSetNull extends AbstractTestUI { - public static String EMPTY_SELECTION_TEXT = "Empty Selection"; - - @Override - protected void setup(VaadinRequest request) { - NativeSelect<Integer> select = new NativeSelect<>("Native Selection"); - - // Add some items - select.setItems(1, 2, 3, 45, 6); - select.setEmptySelectionAllowed(true); - select.setEmptySelectionCaption(EMPTY_SELECTION_TEXT); - - Button changeSelect = new Button("Set value to 3", - e -> select.setValue(3)); - changeSelect.setId("changeSelect"); - Button setNull = new Button("Set value to null", - e -> select.setValue(null)); - setNull.setId("setNull"); - Button clear = new Button("Clear", e -> select.clear()); - clear.setId("clear"); - - Button disable = new Button("Disable", e -> select - .setEmptySelectionAllowed(!select.isEmptySelectionAllowed())); - disable.setId("disable"); - - addComponent(select); - addComponents(changeSelect, setNull, clear, disable); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectSetNullTest.java b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectSetNullTest.java deleted file mode 100644 index 90afe9f463..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectSetNullTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.vaadin.tests.components.nativeselect; - -import com.vaadin.testbench.elements.NativeSelectElement; -import com.vaadin.tests.tb3.MultiBrowserTest; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import static junit.framework.TestCase.assertEquals; - -public class NativeSelectSetNullTest extends MultiBrowserTest { - - @Before - public void setUp() { - openTestURL(); - } - - @Test - public void testCaptionSelected() { - getButtonOnId("setNull"); - assertEquals(NativeSelectSetNull.EMPTY_SELECTION_TEXT, - getSelect().getValue()); - } - - @Test - public void changeSelectedValue() { - getButtonOnId("changeSelect").click(); - assertEquals(3, Integer.valueOf(getSelect().getValue()).intValue()); - } - - @Test - public void clearSelection() { - getButtonOnId("clear").click(); - assertEquals(NativeSelectSetNull.EMPTY_SELECTION_TEXT, - getSelect().getValue()); - } - - @Test - public void valuePreservedAfterAllowEmptySelectionChanged() { - getSelect().setValue("2"); - getButtonOnId("disable").click(); - assertEquals(2, Integer.valueOf(getSelect().getValue()).intValue()); - - getButtonOnId("disable").click(); - getButtonOnId("setNull").click(); - assertEquals(NativeSelectSetNull.EMPTY_SELECTION_TEXT, - getSelect().getValue()); - - } - - protected NativeSelectElement getSelect() { - return $(NativeSelectElement.class).first(); - } - - protected WebElement getButtonOnId(String id) { - return findElement(By.id(id)); - } -} |