Search in sources :

Example 11 with Element

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

the class SynchronizedPropertyView method addSyncWithInitialValue.

private void addSyncWithInitialValue() {
    add(new Text("Synchronized on 'change' event with initial value"));
    final Div syncOnChangeInitialValueLabel = new Div();
    syncOnChangeInitialValueLabel.setId("syncOnChangeInitialValueLabel");
    Element syncOnChangeInitialValue = ElementFactory.createInput();
    syncOnChangeInitialValueLabel.setText("Server value on create: " + syncOnChangeInitialValue.getProperty("value"));
    syncOnChangeInitialValue.setAttribute("id", "syncOnChangeInitialValue");
    syncOnChangeInitialValue.synchronizeProperty("value", "change");
    syncOnChangeInitialValue.addEventListener("change", e -> {
        syncOnChangeInitialValueLabel.setText("Server value in change listener: " + syncOnChangeInitialValue.getProperty("value"));
    });
    syncOnChangeInitialValue.setProperty("value", "initial");
    getElement().appendChild(syncOnChangeInitialValue);
    add(syncOnChangeInitialValueLabel);
}
Also used : Div(com.vaadin.flow.component.html.Div) Element(com.vaadin.flow.dom.Element) Text(com.vaadin.flow.component.Text)

Example 12 with Element

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

the class AttachExistingElementFeatureTest method unregister_dataIsNotAvailaleByNode.

@Test
public void unregister_dataIsNotAvailaleByNode() {
    StateNode node = new StateNode();
    AttachExistingElementFeature feature = new AttachExistingElementFeature(node);
    Element element = Mockito.mock(Element.class);
    StateNode child = Mockito.mock(StateNode.class);
    ChildElementConsumer callback = Mockito.mock(ChildElementConsumer.class);
    Node<?> parent = Mockito.mock(Node.class);
    feature.register(parent, element, child, callback);
    feature.unregister(child);
    Assert.assertNull(feature.getCallback(child));
    Assert.assertNull(feature.getParent(child));
    Assert.assertNull(feature.getPreviousSibling(child));
}
Also used : ChildElementConsumer(com.vaadin.flow.dom.ChildElementConsumer) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) AttachExistingElementFeature(com.vaadin.flow.internal.nodefeature.AttachExistingElementFeature) Test(org.junit.Test)

Example 13 with Element

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

the class AttachExistingElementFeatureTest method forEachChild_register_registeredStatNodeIsAChild.

@Test
public void forEachChild_register_registeredStatNodeIsAChild() {
    StateNode node = new StateNode();
    AttachExistingElementFeature feature = new AttachExistingElementFeature(node);
    Element element = Mockito.mock(Element.class);
    StateNode child = Mockito.mock(StateNode.class);
    ChildElementConsumer callback = Mockito.mock(ChildElementConsumer.class);
    Node<?> parent = Mockito.mock(Node.class);
    feature.register(parent, element, child, callback);
    List<StateNode> children = new ArrayList<>(1);
    feature.forEachChild(children::add);
    Assert.assertEquals(1, children.size());
    Assert.assertEquals(child, children.get(0));
}
Also used : ChildElementConsumer(com.vaadin.flow.dom.ChildElementConsumer) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) ArrayList(java.util.ArrayList) AttachExistingElementFeature(com.vaadin.flow.internal.nodefeature.AttachExistingElementFeature) Test(org.junit.Test)

Example 14 with Element

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

the class ElementListenersTest method testEventDataInEvent.

@Test
public void testEventDataInEvent() {
    AtomicReference<JsonObject> eventDataReference = new AtomicReference<>();
    ns.add("foo", e -> {
        Assert.assertNull(eventDataReference.get());
        eventDataReference.set(e.getEventData());
    }, new String[0]);
    Assert.assertNull(eventDataReference.get());
    JsonObject eventData = Json.createObject();
    eventData.put("baz", true);
    ns.fireEvent(new DomEvent(new Element("element"), "foo", eventData));
    JsonObject capturedJson = eventDataReference.get();
    Assert.assertNotNull(capturedJson);
    Assert.assertEquals(1, capturedJson.keys().length);
    Assert.assertEquals("true", capturedJson.get("baz").toJson());
}
Also used : Element(com.vaadin.flow.dom.Element) JsonObject(elemental.json.JsonObject) AtomicReference(java.util.concurrent.atomic.AtomicReference) DomEvent(com.vaadin.flow.dom.DomEvent) Test(org.junit.Test)

Example 15 with Element

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

the class EventUtilTest method collectBeforeNavigationObserversFromComponentList_elementHasVirtualChildren.

@Test
public void collectBeforeNavigationObserversFromComponentList_elementHasVirtualChildren() throws Exception {
    Foo foo = new Foo();
    foo.getElement().getStateProvider().appendVirtualChild(foo.getElement().getNode(), new EnterObserver().getElement(), NodeProperties.INJECT_BY_ID, "id");
    Bar bar = new Bar();
    Element nested = new Element("nested");
    nested.appendVirtualChild(new Element("nested-child"), new EnterObserver().getElement());
    bar.getElement().appendChild(new Foo().getElement(), nested);
    List<BeforeEnterObserver> beforeNavigationObservers = EventUtil.collectBeforeEnterObservers(Arrays.asList(foo, bar));
    Assert.assertEquals("Wrong amount of listener instances found", 2, beforeNavigationObservers.size());
}
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