-
Notifications
You must be signed in to change notification settings - Fork 188
Labels
Description
Describe your motivation
A Signal binding for CSS class name that tracks class name toggles automatically with no need to call set(String className, boolean set) manually - less boilerplate for common “toggle class by state” use cases.
Consistent behavior with other bindXyz patterns (e.g., throwing when a binding is active).
Describe the solution you'd like
Add a new method to com.vaadin.flow.dom.ClassList:
void bind(String name, Signal<Boolean> signal)- when bound, the presence of the class name mirrors
signal.value() - while a binding for name is active:
- manually adding/removing that specific class throws
BindingActiveException - signal effect is active when the owner element is attached, and deactivated otherwise.
- manually adding/removing that specific class throws
- bulk operations that indiscriminately replace/clear classes (e.g.,
element.getClassList().clear()orelement.setAttribute("class", "foo")) silently clear all signal bindings. - passing
nulltobindmethod removes binding the binding.
Example usage:
Signal<Boolean> highlight = new ValueSignal<Boolean>(false);
Span span = new Span("Hello");
span.getElement().getClassList().bind("highlight", highlight);
// Later:
highlight.value(true); // "highlight" class is added
// span.getElement().getClassList().add("highlight"); // throws BindingActiveException while boundAdditional context
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
🔎Iteration reviews
Status
Next for Dev. Team