Search in sources :

Example 56 with Element

use of com.vaadin.flow.dom.Element in project flow by vaadin.

the class HTMLTest method rootSpecialAttributes.

@Test
public void rootSpecialAttributes() {
    Html html = new Html("<span class='foo' style='color: red'>hello</span>");
    Element element = html.getElement();
    Assert.assertEquals(Tag.SPAN, element.getTag());
    Assert.assertEquals(2, element.getAttributeNames().count());
    Assert.assertEquals("foo", element.getAttribute("class"));
    Assert.assertEquals("color:red", element.getAttribute("style"));
    Assert.assertEquals("hello", html.getInnerHtml());
}
Also used : Element(com.vaadin.flow.dom.Element) Html(com.vaadin.flow.component.Html) Test(org.junit.Test)

Example 57 with Element

use of com.vaadin.flow.dom.Element in project flow by vaadin.

the class ComponentTest method assertPropertyOrAttribute.

private static void assertPropertyOrAttribute(Component component, String propertyOrAttribute) {
    Element element = component.getElement();
    Assert.assertNotEquals(element.hasAttribute(propertyOrAttribute), element.hasProperty(propertyOrAttribute));
}
Also used : Element(com.vaadin.flow.dom.Element)

Example 58 with Element

use of com.vaadin.flow.dom.Element in project flow by vaadin.

the class ComponentEventBus method addDomTrigger.

/**
 * Adds a DOM listener of the given type for the given component event.
 * <p>
 * Assumes that no listener exists.
 *
 * @param eventType
 *            the component event type
 * @param domEventType
 *            the DOM event type
 */
private void addDomTrigger(Class<? extends ComponentEvent<?>> eventType, String domEventType) {
    assert eventType != null;
    assert !componentEventData.containsKey(eventType) || componentEventData.get(eventType).domEventRemover == null;
    if (domEventType == null || domEventType.isEmpty()) {
        throw new IllegalArgumentException("The DOM event type cannot be null or empty");
    }
    Element element = component.getElement();
    // Register DOM event handler
    LinkedHashMap<String, Class<?>> eventDataExpressions = ComponentEventBusUtil.getEventDataExpressions(eventType);
    String[] eventData = new String[eventDataExpressions.size()];
    eventDataExpressions.keySet().toArray(eventData);
    // This needs to be an anonymous class and not a lambda because of
    // https://github.com/vaadin/flow/issues/575
    Registration remover = element.addEventListener(domEventType, event -> handleDomEvent(eventType, event), eventData);
    componentEventData.computeIfAbsent(eventType, t -> new ComponentEventData()).domEventRemover = remover;
}
Also used : Registration(com.vaadin.flow.shared.Registration) Element(com.vaadin.flow.dom.Element)

Example 59 with Element

use of com.vaadin.flow.dom.Element in project flow by vaadin.

the class Composite method setContent.

/**
 * Sets the content for this composite and attaches it to the element.
 * <p>
 * This method must only be called once.
 *
 * @param content
 *            the content for the composite
 */
private void setContent(T content) {
    assert content.getElement().getComponent().isPresent() : "Composite should never be attached to an element which is not attached to a component";
    assert this.content == null : "Content has already been initialized";
    this.content = content;
    Element element = content.getElement();
    // Always replace the composite reference as this will be called from
    // inside out, so the end result is that the element refers to the
    // outermost composite in the probably rare case that multiple
    // composites are nested
    ElementUtil.setComponent(element, this);
}
Also used : Element(com.vaadin.flow.dom.Element)

Example 60 with Element

use of com.vaadin.flow.dom.Element in project flow by vaadin.

the class ElementTest method addAsChildOfChild.

@Test(expected = IllegalStateException.class)
public void addAsChildOfChild() {
    Element parent = ElementFactory.createDiv();
    Element child = ElementFactory.createDiv();
    parent.appendChild(child);
    child.appendChild(parent);
}
Also used : Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Aggregations

Element (com.vaadin.flow.dom.Element)377 Test (org.junit.Test)322 UI (com.vaadin.flow.component.UI)42 StateNode (com.vaadin.flow.internal.StateNode)32 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)29 Style (com.vaadin.flow.dom.Style)25 StreamResource (com.vaadin.flow.server.StreamResource)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 ArrayList (java.util.ArrayList)14 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)13 JsonObject (elemental.json.JsonObject)12 WeakReference (java.lang.ref.WeakReference)12 URI (java.net.URI)11 ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)10 Registration (com.vaadin.flow.shared.Registration)10 JsonValue (elemental.json.JsonValue)10 ShadowRoot (com.vaadin.flow.dom.ShadowRoot)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 ChildElementConsumer (com.vaadin.flow.dom.ChildElementConsumer)8 AttachExistingElementFeature (com.vaadin.flow.internal.nodefeature.AttachExistingElementFeature)8