Skip to content

Commit c7d78d0

Browse files
Felipe Langpaodb
authored andcommitted
fix: remove any existing input-mask children from parent
1 parent ebfc397 commit c7d78d0

File tree

1 file changed

+8
-1
lines changed
  • vcf-input-mask/src/main/java/com/vaadin/componentfactory/addons/inputmask

1 file changed

+8
-1
lines changed

vcf-input-mask/src/main/java/com/vaadin/componentfactory/addons/inputmask/InputMask.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.vaadin.flow.component.UI;
2424
import com.vaadin.flow.component.dependency.JsModule;
2525
import com.vaadin.flow.component.dependency.NpmPackage;
26+
import com.vaadin.flow.dom.Element;
2627
import com.vaadin.flow.function.SerializableConsumer;
2728
import com.vaadin.flow.shared.Registration;
2829
import java.lang.ref.WeakReference;
@@ -74,7 +75,13 @@ private void extend(Component component, UI ui) {
7475
getElement().setProperty("options", objectMapper.writeValueAsString(options));
7576

7677
extended = new WeakReference<Component>(component);
77-
component.getElement().appendChild(getElement());
78+
79+
Element componentElement = component.getElement();
80+
// remove any existing input-mask element attached to component
81+
componentElement.getChildren()
82+
.filter(child -> TAG_NAME.equalsIgnoreCase(child.getTag()))
83+
.findAny().ifPresent(componentElement::removeChild);
84+
componentElement.appendChild(getElement());
7885

7986
if (HasValue.class.isAssignableFrom(component.getClass())) {
8087
valueChangeRegistration = HasValue.class.cast(component).addValueChangeListener(e -> {

0 commit comments

Comments
 (0)