diff options
author | Anastasia Smirnova <anasmi@utu.fi> | 2018-03-13 02:20:58 -1200 |
---|---|---|
committer | Ilia Motornyi <elmot@vaadin.com> | 2018-03-13 17:20:58 +0300 |
commit | 4fc7530ded4a3775e3e9c7343e026a624ce00079 (patch) | |
tree | 6af9607b4270ac6ba6f04d686ceaab89bf627413 | |
parent | e813c97e0bdc00c5542c9bf0f55eef65f34ac093 (diff) | |
download | vaadin-framework-4fc7530ded4a3775e3e9c7343e026a624ce00079.tar.gz vaadin-framework-4fc7530ded4a3775e3e9c7343e026a624ce00079.zip |
Native select add 'disabled' attribute (#10710)
* Adding disabled attribute to the NativeSelect
* Merge branch 'master' into nativeSelectDisabled
* Merge branch 'master' into nativeSelectDisabled
* Correct formatting issues
4 files changed, 65 insertions, 1 deletions
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 c814a72fdf..9041751480 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 @@ -150,4 +150,16 @@ public class NativeSelectConnector } updateSelectedItem(); } + + @Override + public void setWidgetEnabled(boolean widgetEnabled) { + // add or remove v-disabled style name from the widget + super.setWidgetEnabled(widgetEnabled); + if (widgetEnabled) { + getWidget().getListBox().getElement().removeAttribute("disabled"); + } else { + getWidget().getListBox().getElement() + .setAttribute("disabled", "disabled"); + } + } } diff --git a/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectDisabled.java b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectDisabled.java new file mode 100644 index 0000000000..885b701517 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectDisabled.java @@ -0,0 +1,27 @@ +package com.vaadin.tests.components.nativeselect; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.NativeSelect; + +/** + * @author Vaadin Ltd + * + */ +@Widgetset("com.vaadin.DefaultWidgetSet") +public class NativeSelectDisabled extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + NativeSelect<String> select = new NativeSelect<>(); + select.setItems("Foo", "Bar"); + select.setValue("Bar"); + select.setEnabled(false); + addButton("Set Enabled/Disabled", event -> { + select.setEnabled(!select.isEnabled()); + }); + addComponent(select); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectDisabledTest.java b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectDisabledTest.java new file mode 100644 index 0000000000..fe01ef90ad --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectDisabledTest.java @@ -0,0 +1,26 @@ +package com.vaadin.tests.components.nativeselect; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.NativeSelectElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class NativeSelectDisabledTest extends MultiBrowserTest { + + @Test + public void testDisabled() { + openTestURL(); + + NativeSelectElement el = $(NativeSelectElement.class).first(); + assertEquals(false, el.isEnabled()); + ButtonElement but = $(ButtonElement.class).first(); + but.click(); + assertEquals(true, el.isEnabled()); + assertEquals(null, el.getSelectElement().getAttribute("disabled")); + but.click(); + System.out.println(el.getSelectElement().getText()); + assertEquals("true", el.getSelectElement().getAttribute("disabled")); + } +}
\ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectInitTest.java b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectInitTest.java index 4f48d7a1ce..10a78e4fc5 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectInitTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectInitTest.java @@ -35,5 +35,4 @@ public class NativeSelectInitTest extends MultiBrowserTest { String selected = $(NativeSelectElement.class).first().getValue(); assertEquals("Bar", selected); } - } |