diff options
author | Anastasia Smirnova <anasmi@utu.fi> | 2018-04-20 09:59:44 +0300 |
---|---|---|
committer | Ilia Motornyi <elmot@vaadin.com> | 2018-04-20 09:59:44 +0300 |
commit | 3ffb27fa734195f103fdbfb5ad6c81d7a8b006f7 (patch) | |
tree | 18290c97503062b18defdbe5de29668c093c26f2 | |
parent | d543e47becc77e5b18c69a416e6e84122ac10fe1 (diff) | |
download | vaadin-framework-3ffb27fa734195f103fdbfb5ad6c81d7a8b006f7.tar.gz vaadin-framework-3ffb27fa734195f103fdbfb5ad6c81d7a8b006f7.zip |
Fix RichTextArea read-only+disabled
Resolves #10541
3 files changed, 73 insertions, 2 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VRichTextArea.java b/client/src/main/java/com/vaadin/client/ui/VRichTextArea.java index 4f436bf51d..1ed07c4cec 100644 --- a/client/src/main/java/com/vaadin/client/ui/VRichTextArea.java +++ b/client/src/main/java/com/vaadin/client/ui/VRichTextArea.java @@ -163,8 +163,8 @@ public class VRichTextArea extends Composite implements Field, KeyPressHandler, public void setEnabled(boolean enabled) { if (this.enabled != enabled) { // rta.setEnabled(enabled); - swapEditableArea(); this.enabled = enabled; + swapEditableArea(); } } @@ -179,6 +179,9 @@ public class VRichTextArea extends Composite implements Field, KeyPressHandler, private void swapEditableArea() { String value = getValue(); if (html.isAttached()) { + if (isReadOnly() || !isEnabled()) { + return; + } fp.remove(html); if (BrowserInfo.get().isWebkit()) { fp.remove(formatter); @@ -218,8 +221,8 @@ public class VRichTextArea extends Composite implements Field, KeyPressHandler, public void setReadOnly(boolean b) { if (isReadOnly() != b) { - swapEditableArea(); readOnly = b; + swapEditableArea(); } // reset visibility in case enabled state changed and the formatter was // recreated diff --git a/uitest/src/main/java/com/vaadin/tests/components/richtextarea/RichTextAreaReadOnlyDisabled.java b/uitest/src/main/java/com/vaadin/tests/components/richtextarea/RichTextAreaReadOnlyDisabled.java new file mode 100644 index 0000000000..d9c8c22811 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/richtextarea/RichTextAreaReadOnlyDisabled.java @@ -0,0 +1,31 @@ +package com.vaadin.tests.components.richtextarea; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.RichTextArea; + +public class RichTextAreaReadOnlyDisabled extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + RichTextArea readOnlyDisabledTextArea = new RichTextArea( + "Readonly & Disabled"); + readOnlyDisabledTextArea.setReadOnly(true); + readOnlyDisabledTextArea.setEnabled(false); + readOnlyDisabledTextArea.setValue("Random value"); + readOnlyDisabledTextArea.setId("rtA"); + + final Button but1 = new Button("set Read ", + event -> readOnlyDisabledTextArea + .setReadOnly(!readOnlyDisabledTextArea.isReadOnly())); + but1.setId("readPr"); + final Button but2 = new Button("Enable/Disable ", + event -> readOnlyDisabledTextArea + .setEnabled(!readOnlyDisabledTextArea.isEnabled())); + but2.setId("enablePr"); + addComponent(readOnlyDisabledTextArea); + addComponent(but1); + addComponent(but2); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/richtextarea/RichTextAreaReadOnlyDisabledTest.java b/uitest/src/test/java/com/vaadin/tests/components/richtextarea/RichTextAreaReadOnlyDisabledTest.java new file mode 100644 index 0000000000..83b1c41edc --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/richtextarea/RichTextAreaReadOnlyDisabledTest.java @@ -0,0 +1,37 @@ +package com.vaadin.tests.components.richtextarea; + +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.DesiredCapabilities; + +import java.util.List; + +public class RichTextAreaReadOnlyDisabledTest extends MultiBrowserTest { + + @Override + public List<DesiredCapabilities> getBrowsersToTest() { + return getBrowsersExcludingPhantomJS(); + } + + @Test + public void shouldDelegateToShortcutActionHandler() { + openTestURL(); + // gwt-RichTextArea is classname used by iframe + WebElement readPrB = findElement(By.id("readPr")); + WebElement enablePrB = findElement(By.id("enablePr")); + + assertElementNotPresent(By.className("gwt-RichTextArea")); + readPrB.click(); + + assertElementNotPresent(By.className("gwt-RichTextArea")); + enablePrB.click(); + + assertElementPresent(By.className("gwt-RichTextArea")); + readPrB.click();//Set to read-only + assertElementNotPresent(By.className("gwt-RichTextArea")); + enablePrB.click();//Set disabled + assertElementNotPresent(By.className("gwt-RichTextArea")); + } +} |