diff --git a/flow-html-components/src/main/java/com/vaadin/flow/component/html/Anchor.java b/flow-html-components/src/main/java/com/vaadin/flow/component/html/Anchor.java index 6e513beef0d..fc0ee38469a 100644 --- a/flow-html-components/src/main/java/com/vaadin/flow/component/html/Anchor.java +++ b/flow-html-components/src/main/java/com/vaadin/flow/component/html/Anchor.java @@ -43,9 +43,6 @@ public class Anchor extends HtmlContainer implements Focusable { .optionalAttributeWithDefault("target", AnchorTarget.DEFAULT.getValue()); - private String disabledHref; - private AbstractStreamResource resource; - /** * Creates a new empty anchor component. */ @@ -157,7 +154,6 @@ public void removeHref() { * the resource value, not null */ public void setHref(AbstractStreamResource href) { - resource = href; getElement().setAttribute("href", href); } @@ -249,36 +245,4 @@ public AnchorTargetValue getTargetValue() { return AnchorTarget.DEFAULT; } - @Override - public void onEnabledStateChanged(boolean enabled) { - super.onEnabledStateChanged(enabled); - if (enabled) { - if (resource == null) { - restoreHref(); - } else { - restoreResource(); - } - disabledHref = null; - } else { - disabledHref = getHref(); - removeHref(); - } - } - - private void restoreHref() { - if (!getElement().hasAttribute("href")) { - // only set attribute value back if attribute has not been set - // somehow when component was disabled - setHref(disabledHref); - } - } - - private void restoreResource() { - if (!getElement().hasAttribute("href")) { - // only set attribute value back if attribute has not been set - // somehow when component was disabled - setHref(resource); - } - } - } diff --git a/flow-html-components/src/test/java/com/vaadin/flow/component/html/AnchorTest.java b/flow-html-components/src/test/java/com/vaadin/flow/component/html/AnchorTest.java index 9bfeb3722f5..24bd7cfed91 100644 --- a/flow-html-components/src/test/java/com/vaadin/flow/component/html/AnchorTest.java +++ b/flow-html-components/src/test/java/com/vaadin/flow/component/html/AnchorTest.java @@ -17,24 +17,13 @@ import java.util.Optional; -import org.junit.After; import org.junit.Assert; import org.junit.Test; import com.vaadin.flow.component.Text; -import com.vaadin.flow.component.UI; -import com.vaadin.flow.server.AbstractStreamResource; public class AnchorTest extends ComponentTest { - private UI ui; - - @After - public void tearDown() { - ui = null; - UI.setCurrent(null); - } - @Test public void removeHref() { Anchor anchor = new Anchor(); @@ -110,120 +99,6 @@ public void getTargetValue_useSomeStringValue_targetIsReturned() { Assert.assertEquals("foo", anchor.getTargetValue().getValue()); } - @Test - public void disabledAnchor_hrefIsRemoved_enableAnchor_hrefIsRestored() { - Anchor anchor = new Anchor("foo", "bar"); - anchor.setEnabled(false); - - Assert.assertFalse(anchor.getElement().hasAttribute("href")); - - anchor.setEnabled(true); - Assert.assertTrue(anchor.getElement().hasAttribute("href")); - Assert.assertEquals("foo", anchor.getHref()); - } - - @Test - public void disabledAnchor_setHrefWhenDisabled_enableAnchor_hrefIsPreserved() { - Anchor anchor = new Anchor("foo", "bar"); - anchor.setEnabled(false); - - anchor.setHref("baz"); - - anchor.setEnabled(true); - - Assert.assertTrue(anchor.getElement().hasAttribute("href")); - Assert.assertEquals("baz", anchor.getHref()); - } - - @Test - public void disabledAnchor_setResourceWhenDisabled_enableAnchor_resourceIsPreserved() { - Anchor anchor = new Anchor("foo", "bar"); - anchor.setEnabled(false); - - mockUI(); - anchor.setHref(new AbstractStreamResource() { - - @Override - public String getName() { - return "baz"; - } - }); - String href = anchor.getHref(); - - anchor.setEnabled(true); - - Assert.assertTrue(anchor.getElement().hasAttribute("href")); - Assert.assertEquals(href, anchor.getHref()); - } - - @Test - public void disabledAnchor_setResource_hrefIsRemoved_enableAnchor_hrefIsRestored() { - mockUI(); - AbstractStreamResource resource = new AbstractStreamResource() { - - @Override - public String getName() { - return "foo"; - } - - }; - Anchor anchor = new Anchor(resource, "bar"); - String href = anchor.getHref(); - anchor.setEnabled(false); - - Assert.assertFalse(anchor.getElement().hasAttribute("href")); - - anchor.setEnabled(true); - Assert.assertEquals(href, anchor.getHref()); - } - - @Test - public void disabledAnchor_setResourceWhenDisabled_hrefIsPreserved() { - mockUI(); - AbstractStreamResource resource = new AbstractStreamResource() { - - @Override - public String getName() { - return "foo"; - } - - }; - Anchor anchor = new Anchor(resource, "bar"); - String href = anchor.getHref(); - anchor.setEnabled(false); - - anchor.setHref(new AbstractStreamResource() { - - @Override - public String getName() { - return "baz"; - } - }); - - Assert.assertTrue(anchor.getElement().hasAttribute("href")); - Assert.assertNotEquals(href, anchor.getHref()); - } - - @Test - public void disabledAnchor_setResource_setHrefViaElementWhenDisabled_enableAnchor_hrefIsRestored() { - mockUI(); - AbstractStreamResource resource = new AbstractStreamResource() { - - @Override - public String getName() { - return "foo"; - } - - }; - Anchor anchor = new Anchor(resource, "bar"); - anchor.setEnabled(false); - - anchor.getElement().setAttribute("href", "baz"); - - anchor.setEnabled(true); - Assert.assertEquals("baz", anchor.getHref()); - } - // Other test methods in super class @Override @@ -232,9 +107,4 @@ protected void addProperties() { addOptionalStringProperty("target"); } - private void mockUI() { - ui = new UI(); - UI.setCurrent(ui); - } - }