diff --git a/flow-client/src/main/java/com/vaadin/client/ElementUtils.java b/flow-client/src/main/java/com/vaadin/client/ElementUtils.java index 96be78ff77c..ba40fe71059 100644 --- a/flow-client/src/main/java/com/vaadin/client/ElementUtils.java +++ b/flow-client/src/main/java/com/vaadin/client/ElementUtils.java @@ -162,15 +162,7 @@ public static void attachExistingElementById(StateNode parent, private static native Element getDomElementById(Element shadowRootParent, String id) /*-{ - var elementById = null; - var shadowRoot = shadowRootParent.shadowRoot; - if (shadowRoot && typeof(shadowRoot.getElementById) === 'function') { - elementById = shadowRoot.getElementById(id); - } - if(elementById == null) { - elementById = $doc.getElementById(id); - } - return elementById; + return shadowRootParent.$[id]; }-*/; private static Integer getExistingIdOrUpdate(StateNode parent, diff --git a/flow-client/src/test-gwt/java/com/vaadin/client/GwtElementUtilsTest.java b/flow-client/src/test-gwt/java/com/vaadin/client/GwtElementUtilsTest.java index 4f4fc971046..5d1ab877d4f 100644 --- a/flow-client/src/test-gwt/java/com/vaadin/client/GwtElementUtilsTest.java +++ b/flow-client/src/test-gwt/java/com/vaadin/client/GwtElementUtilsTest.java @@ -165,13 +165,13 @@ public void testAttachExistingElement_noRequestedElement() { } public void testAttachExistingElementById_elementExistsInDom() { - Element shadowRoot = setupShadowRoot(); + setupShadowRoot(); String id = "identifier"; Element child = Browser.getDocument().createElement("div"); child.setAttribute("id", id); - shadowRoot.appendChild(child); + addChildElement(element, child); ElementUtils.attachExistingElementById(node, "div", requestedId, id); @@ -189,13 +189,12 @@ public void testAttachExistingElementById_elementMissingInDom() { } public void testAttachExistingElementById_elementIsAlreadyAssociated() { - Element shadowRoot = setupShadowRoot(); - + setupShadowRoot(); String id = "identifier"; Element child = Browser.getDocument().createElement("div"); child.setAttribute("id", id); - shadowRoot.appendChild(child); + addChildElement(element, child); NodeMap map = node.getMap(NodeFeatures.SHADOW_ROOT_DATA); @@ -215,70 +214,21 @@ public void testAttachExistingElementById_elementIsAlreadyAssociated() { assertRpcToServerArguments(99, child.getTagName(), id); } - // This test emulates FireFox that doesn't hide element children under shadowRoot - public void testAttachExistingElementById_elementOutsideShadowRoot() { - Browser.getDocument().getBody().appendChild(element); - setupShadowRoot(); - - String id = "identifier"; - - Element child = Browser.getDocument().createElement("div"); - child.setAttribute("id", id); - element.appendChild(child); - - ElementUtils.attachExistingElementById(node, - "div", requestedId, id); - - assertRpcToServerArguments(requestedId, child.getTagName(), id); - } - - // This test emulates Edge that doesn't support requesting getElementById from shadowRoot - public void testAttachExistingElementById_noByIdMethodInShadowRoot() { - Browser.getDocument().getBody().appendChild(element); - Element shadowRoot = addShadowRootWithoutGetElementById(element); - - NodeMap map = node.getMap(NodeFeatures.SHADOW_ROOT_DATA); - map.getProperty(NodeFeatures.SHADOW_ROOT).setValue(new StateNode(34, tree)); - - String id = "identifier"; - - Element child = Browser.getDocument().createElement("div"); - child.setAttribute("id", id); - element.appendChild(child); - - ElementUtils.attachExistingElementById(node, - "div", requestedId, id); - - assertRpcToServerArguments(requestedId, child.getTagName(), id); - } - - private Element setupShadowRoot() { - Element shadowRoot = addShadowRoot(element); + private void setupShadowRoot() { + setupParent(element); NodeMap map = node.getMap(NodeFeatures.SHADOW_ROOT_DATA); map.getProperty(NodeFeatures.SHADOW_ROOT).setValue(new StateNode(34, tree)); - - return shadowRoot; } - private native Element addShadowRoot(Element element) /*-{ - element.shadowRoot = $doc.createElement("div"); - element.shadowRoot.getElementById = function(id) { - var children = element.shadowRoot.children; - for (var i = 0; i < children.length; i++) { - var child = children[i]; - if(child.getAttribute("id") === id) { - return child; - } - } + private native void setupParent(Element element) /*-{ + element.$ = function() { + return element; } - - return element.shadowRoot; }-*/; - private native Element addShadowRootWithoutGetElementById(Element element) /*-{ - element.shadowRoot = $doc.createElement("div"); - return element.shadowRoot; + private native void addChildElement(Element parent, Element child) /*-{ + parent.$[child.getAttribute("id")] = child; }-*/; private void assertRpcToServerArguments(int associatedId, String tagName,