Search in sources :

Example 1 with DomTokenList

use of com.vaadin.client.flow.dom.DomElement.DomTokenList in project flow by vaadin.

the class SimpleElementBindingStrategy method bindClassList.

private EventRemover bindClassList(Element element, StateNode node) {
    NodeList classNodeList = node.getList(NodeFeatures.CLASS_LIST);
    for (int i = 0; i < classNodeList.length(); i++) {
        DomApi.wrap(element).getClassList().add((String) classNodeList.get(i));
    }
    return classNodeList.addSpliceListener(e -> {
        DomTokenList classList = DomApi.wrap(element).getClassList();
        JsArray<?> remove = e.getRemove();
        for (int i = 0; i < remove.length(); i++) {
            classList.remove((String) remove.get(i));
        }
        JsArray<?> add = e.getAdd();
        for (int i = 0; i < add.length(); i++) {
            classList.add((String) add.get(i));
        }
    });
}
Also used : NodeList(com.vaadin.client.flow.nodefeature.NodeList) DomTokenList(com.vaadin.client.flow.dom.DomElement.DomTokenList)

Aggregations

DomTokenList (com.vaadin.client.flow.dom.DomElement.DomTokenList)1 NodeList (com.vaadin.client.flow.nodefeature.NodeList)1