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 e4b8f24cbb9..19f6ae8d168 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 { private static final String ROUTER_IGNORE_ATTRIBUTE = "router-ignore"; - private String disabledHref; - private AbstractStreamResource resource; - /** * Creates a new empty anchor component. */ @@ -137,7 +134,6 @@ public void removeHref() { * the resource value, not null */ public void setHref(AbstractStreamResource href) { - resource = href; getElement().setAttribute("href", href); getElement().setAttribute(ROUTER_IGNORE_ATTRIBUTE, true); } @@ -187,36 +183,4 @@ public Optional getTarget() { return get(targetDescriptor); } - @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 afbf21f93b1..c25816bc4fe 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 @@ -15,24 +15,13 @@ */ package com.vaadin.flow.component.html; -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(); @@ -72,120 +61,6 @@ public void shouldNotBreakBehaviorIfSetHrefWhenHavingRouterIgnoreAttributeBefore anchor.getElement().getAttribute("router-ignore")); } - @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 @@ -194,9 +69,4 @@ protected void addProperties() { addOptionalStringProperty("target"); } - private void mockUI() { - ui = new UI(); - UI.setCurrent(ui); - } - }