Search in sources :

Example 1 with ClassList

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

the class ElementTest method testContainsClassWithSpaces.

@Test
public void testContainsClassWithSpaces() {
    ClassList cl = ElementFactory.createDiv().getClassList();
    cl.add("foo");
    cl.add("bar");
    Assert.assertFalse(cl.contains("foo bar"));
}
Also used : ClassList(com.vaadin.flow.dom.ClassList) Test(org.junit.Test)

Example 2 with ClassList

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

the class ElementTest method testRemoveClassWithSpaces.

@Test
public void testRemoveClassWithSpaces() {
    ClassList cl = ElementFactory.createDiv().getClassList();
    cl.add("foo");
    cl.add("bar");
    cl.remove("foo bar");
    Assert.assertEquals(2, cl.size());
}
Also used : ClassList(com.vaadin.flow.dom.ClassList) Test(org.junit.Test)

Example 3 with ClassList

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

the class TemplateElementStateProviderTest method dynamicClassNames.

@Test
public void dynamicClassNames() {
    Element element = createElement("<div class='foo' [class.bar]=hasBar [class.baz]=hasBaz></div>");
    ClassList classList = element.getClassList();
    // Explicitly set "hasBar" and "hasBaz" properties to null. So model has
    // properties "hasBar" and "hasBaz".
    // See #970
    element.getNode().getFeature(ModelMap.class).setValue("hasBar", null);
    element.getNode().getFeature(ModelMap.class).setValue("hasBaz", null);
    Assert.assertEquals("foo", element.getAttribute("class"));
    assertClassList(classList, "foo");
    assertNotClassList(classList, "bar", "baz");
    ModelMap modelMap = element.getNode().getFeature(ModelMap.class);
    modelMap.setValue("hasBar", "");
    modelMap.setValue("hasBaz", "yes");
    assertClassList(classList, "foo", "baz");
    assertNotClassList(classList, "bar");
    modelMap.setValue("hasBar", 5);
    modelMap.setValue("hasBaz", 0);
    assertClassList(classList, "foo", "bar");
    assertNotClassList(classList, "baz");
    modelMap.setValue("hasBar", false);
    modelMap.setValue("hasBaz", true);
    assertClassList(classList, "foo", "baz");
    assertNotClassList(classList, "bar");
}
Also used : Element(com.vaadin.flow.dom.Element) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) ClassList(com.vaadin.flow.dom.ClassList) Test(org.junit.Test)

Aggregations

ClassList (com.vaadin.flow.dom.ClassList)3 Test (org.junit.Test)3 Element (com.vaadin.flow.dom.Element)1 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)1