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());
}
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));
}
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;
}
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);
}
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);
}
Aggregations