Skip to content

Commit bae5954

Browse files
refactor!: update ConfirmDialog to not use HasOrderedComponents (#7814)
* refactor!: update ConfirmDialog to not use HasOrderedComponents * refactor: un-deprecate add and remove methods, update removeAll * test: remove not needed logic * Update vaadin-confirm-dialog-flow-parent/vaadin-confirm-dialog-flow/src/main/java/com/vaadin/flow/component/confirmdialog/ConfirmDialog.java Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com> --------- Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com>
1 parent 37f3506 commit bae5954

File tree

2 files changed

+102
-169
lines changed

2 files changed

+102
-169
lines changed

vaadin-confirm-dialog-flow-parent/vaadin-confirm-dialog-flow/src/main/java/com/vaadin/flow/component/confirmdialog/ConfirmDialog.java

Lines changed: 10 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
*/
1616
package com.vaadin.flow.component.confirmdialog;
1717

18-
import java.util.Collection;
1918
import java.util.Optional;
2019

2120
import com.vaadin.flow.component.Component;
2221
import com.vaadin.flow.component.ComponentEvent;
2322
import com.vaadin.flow.component.ComponentEventListener;
2423
import com.vaadin.flow.component.ComponentUtil;
2524
import com.vaadin.flow.component.DomEvent;
26-
import com.vaadin.flow.component.HasOrderedComponents;
25+
import com.vaadin.flow.component.HasComponents;
2726
import com.vaadin.flow.component.HasSize;
2827
import com.vaadin.flow.component.HasStyle;
2928
import com.vaadin.flow.component.Tag;
@@ -62,7 +61,7 @@
6261
@NpmPackage(value = "@vaadin/confirm-dialog", version = "25.0.0-alpha12")
6362
@JsModule("@vaadin/confirm-dialog/src/vaadin-confirm-dialog.js")
6463
public class ConfirmDialog extends Component
65-
implements HasSize, HasStyle, HasOrderedComponents {
64+
implements HasComponents, HasSize, HasStyle {
6665

6766
/**
6867
* Event that is fired when the user clicks the Confirm button
@@ -703,176 +702,18 @@ public void setCloseOnEsc(boolean closeOnEsc) {
703702
}
704703

705704
/**
706-
* Confirm dialog does not support adding content. Use
707-
* {@link #setText(Component)} instead to initialize content as a component.
705+
* {@inheritDoc}
708706
* <p>
709-
* This method is inherited from {@link HasOrderedComponents} and has been
710-
* marked as deprecated to indicate that it is not supported.
711-
*
712-
* @deprecated since v24.4, not supported
713-
*/
714-
@Deprecated
715-
@Override
716-
public void add(Component... components) {
717-
HasOrderedComponents.super.add(components);
718-
}
719-
720-
/**
721-
* Confirm dialog does not support adding content. Use
722-
* {@link #setText(Component)} instead to initialize content as a component.
723-
* <p>
724-
* This method is inherited from {@link HasOrderedComponents} and has been
725-
* marked as deprecated to indicate that it is not supported.
726-
*
727-
* @deprecated since v24.4, not supported
728-
*/
729-
@Deprecated
730-
@Override
731-
public void add(Collection<Component> components) {
732-
HasOrderedComponents.super.add(components);
733-
}
734-
735-
/**
736-
* Confirm dialog does not support adding content. Use
737-
* {@link #setText(String)} instead to initialize content as text.
738-
* <p>
739-
* This method is inherited from {@link HasOrderedComponents} and has been
740-
* marked as deprecated to indicate that it is not supported.
741-
*
742-
* @deprecated since v24.4, not supported
707+
* Removes all components from this component except elements that have slot
708+
* attribute, such as header and buttons.
743709
*/
744-
@Deprecated
745-
@Override
746-
public void add(String text) {
747-
HasOrderedComponents.super.add(text);
748-
}
749-
750-
/**
751-
* Confirm dialog does not support removing content.
752-
* <p>
753-
* This method is inherited from {@link HasOrderedComponents} and has been
754-
* marked as deprecated to indicate that it is not supported.
755-
*
756-
* @deprecated since v24.4, not supported
757-
*/
758-
@Deprecated
759-
@Override
760-
public void remove(Component... components) {
761-
HasOrderedComponents.super.remove(components);
762-
}
763-
764-
/**
765-
* Confirm dialog does not support removing content.
766-
* <p>
767-
* This method is inherited from {@link HasOrderedComponents} and has been
768-
* marked as deprecated to indicate that it is not supported.
769-
*
770-
* @deprecated since v24.4, not supported
771-
*/
772-
@Deprecated
773-
@Override
774-
public void remove(Collection<Component> components) {
775-
HasOrderedComponents.super.remove(components);
776-
}
777-
778-
/**
779-
* Confirm dialog does not support removing content.
780-
* <p>
781-
* This method is inherited from {@link HasOrderedComponents} and has been
782-
* marked as deprecated to indicate that it is not supported.
783-
*
784-
* @deprecated since v24.4, not supported
785-
*/
786-
@Deprecated
787710
@Override
788711
public void removeAll() {
789-
HasOrderedComponents.super.removeAll();
790-
}
791-
792-
/**
793-
* Confirm dialog does not support adding content. Use
794-
* {@link #setText(Component)} instead to initialize content as a component.
795-
* <p>
796-
* This method is inherited from {@link HasOrderedComponents} and has been
797-
* marked as deprecated to indicate that it is not supported.
798-
*
799-
* @deprecated since v24.4, not supported
800-
*/
801-
@Deprecated
802-
@Override
803-
public void addComponentAtIndex(int index, Component component) {
804-
HasOrderedComponents.super.addComponentAtIndex(index, component);
805-
}
806-
807-
/**
808-
* Confirm dialog does not support adding content. Use
809-
* {@link #setText(Component)} instead to initialize content as a component.
810-
* <p>
811-
* This method is inherited from {@link HasOrderedComponents} and has been
812-
* marked as deprecated to indicate that it is not supported.
813-
*
814-
* @deprecated since v24.4, not supported
815-
*/
816-
@Deprecated
817-
@Override
818-
public void addComponentAsFirst(Component component) {
819-
HasOrderedComponents.super.addComponentAsFirst(component);
820-
}
821-
822-
/**
823-
* Confirm dialog does not support replacing content.
824-
* <p>
825-
* This method is inherited from {@link HasOrderedComponents} and has been
826-
* marked as deprecated to indicate that it is not supported.
827-
*
828-
* @deprecated since v24.4, not supported
829-
*/
830-
@Deprecated
831-
@Override
832-
public void replace(Component oldComponent, Component newComponent) {
833-
HasOrderedComponents.super.replace(oldComponent, newComponent);
834-
}
835-
836-
/**
837-
* Confirm dialog does not support multiple components.
838-
* <p>
839-
* This method is inherited from {@link HasOrderedComponents} and has been
840-
* marked as deprecated to indicate that it is not supported.
841-
*
842-
* @deprecated since v24.4, not supported
843-
*/
844-
@Deprecated
845-
@Override
846-
public int indexOf(Component component) {
847-
return HasOrderedComponents.super.indexOf(component);
848-
}
849-
850-
/**
851-
* Confirm dialog does not support multiple components.
852-
* <p>
853-
* This method is inherited from {@link HasOrderedComponents} and has been
854-
* marked as deprecated to indicate that it is not supported.
855-
*
856-
* @deprecated since v24.4, not supported
857-
*/
858-
@Deprecated
859-
@Override
860-
public int getComponentCount() {
861-
return HasOrderedComponents.super.getComponentCount();
862-
}
863-
864-
/**
865-
* Confirm dialog does not support multiple components.
866-
* <p>
867-
* This method is inherited from {@link HasOrderedComponents} and has been
868-
* marked as deprecated to indicate that it is not supported.
869-
*
870-
* @deprecated since v24.4, not supported
871-
*/
872-
@Deprecated
873-
@Override
874-
public Component getComponentAt(int index) {
875-
return HasOrderedComponents.super.getComponentAt(index);
712+
getElement().getChildren().forEach(child -> {
713+
if (!child.hasAttribute("slot")) {
714+
child.removeFromParent();
715+
}
716+
});
876717
}
877718

878719
private void setModality(boolean modal) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2000-2025 Vaadin Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package com.vaadin.flow.component.confirmdialog;
17+
18+
import org.junit.Assert;
19+
import org.junit.Before;
20+
import org.junit.Test;
21+
22+
import com.vaadin.flow.component.html.Div;
23+
24+
public class ConfirmDialogChildrenTest {
25+
26+
private ConfirmDialog dialog;
27+
28+
@Before
29+
public void setup() {
30+
dialog = new ConfirmDialog();
31+
}
32+
33+
@Test
34+
public void add_removeAll_componentIsRemoved() {
35+
Div div = new Div();
36+
dialog.add(div);
37+
38+
dialog.removeAll();
39+
40+
Assert.assertNull(div.getElement().getParent());
41+
}
42+
43+
@Test
44+
public void setText_removeAll_componentIsRemoved() {
45+
Div div = new Div();
46+
dialog.setText(div);
47+
48+
dialog.removeAll();
49+
50+
Assert.assertNull(div.getElement().getParent());
51+
}
52+
53+
@Test
54+
public void setHeader_removeAll_componentIsNotRemoved() {
55+
Div div = new Div();
56+
dialog.setHeader(div);
57+
58+
dialog.removeAll();
59+
60+
Assert.assertEquals(dialog.getElement(), div.getElement().getParent());
61+
}
62+
63+
@Test
64+
public void setConfirmButton_removeAll_componentIsNotRemoved() {
65+
Div div = new Div();
66+
dialog.setConfirmButton(div);
67+
68+
dialog.removeAll();
69+
70+
Assert.assertEquals(dialog.getElement(), div.getElement().getParent());
71+
}
72+
73+
@Test
74+
public void setCancelButton_removeAll_componentIsNotRemoved() {
75+
Div div = new Div();
76+
dialog.setCancelButton(div);
77+
78+
dialog.removeAll();
79+
80+
Assert.assertEquals(dialog.getElement(), div.getElement().getParent());
81+
}
82+
83+
@Test
84+
public void setRejectButton_removeAll_componentIsNotRemoved() {
85+
Div div = new Div();
86+
dialog.setRejectButton(div);
87+
88+
dialog.removeAll();
89+
90+
Assert.assertEquals(dialog.getElement(), div.getElement().getParent());
91+
}
92+
}

0 commit comments

Comments
 (0)