5757
5858public final class VaadinUiUtil {
5959
60+ public static final String FRONT_ELEMENT_STYLE_NAME = "front-element" ;
61+
6062 private VaadinUiUtil () {
6163 // Hide Utility Class Constructor
6264 }
@@ -71,6 +73,20 @@ public static Window createPopupWindow() {
7173 return window ;
7274 }
7375
76+ /**
77+ * Enforces the popup to be in front of other modals.
78+ * Internally uses CSS's z-index to make it work.
79+ *
80+ * @return Window that will stay at front.
81+ */
82+ public static Window createForegroundPopupWindow () {
83+ Window popupWindow = createPopupWindow ();
84+
85+ popupWindow .setStyleName (FRONT_ELEMENT_STYLE_NAME );
86+
87+ return popupWindow ;
88+ }
89+
7490 public static Window showSimplePopupWindow (String caption , String contentText ) {
7591 return showSimplePopupWindow (caption , contentText , ContentMode .TEXT , null );
7692 }
@@ -640,7 +656,7 @@ public static void showWarningPopup(String message) {
640656
641657 public static void addGdprMessageOnClick (TextArea textArea ) {
642658 AtomicBoolean gdprMessageTriggered = new AtomicBoolean (false );
643- Window subWindowGdpR = VaadinUiUtil . createPopupWindow ();
659+ Window subWindowGdpR = createForegroundPopupWindow ();
644660
645661 textArea .addFocusListener (i -> {
646662 showGdprWindow (textArea , gdprMessageTriggered , subWindowGdpR );
@@ -655,12 +671,11 @@ public static void addGdprMessageOnClick(TextArea textArea) {
655671
656672 public static void addGdprMessageOnClick (RichTextArea richTextArea ) {
657673 AtomicBoolean gdprMessageTriggered = new AtomicBoolean (false );
658- Window subWindowGdpR = VaadinUiUtil .createPopupWindow ();
674+ Window subWindowGdpR = VaadinUiUtil .createForegroundPopupWindow ();
659675
660676 richTextArea .addValueChangeListener (event -> {
661677 if (!gdprMessageTriggered .get ()) {
662678 showGdprWindow (richTextArea , gdprMessageTriggered , subWindowGdpR );
663- subWindowGdpR .focus ();
664679 gdprMessageTriggered .set (true );
665680 }
666681 });
@@ -696,6 +711,7 @@ private static void showGdprWindow(AbstractField<?> textArea, AtomicBoolean gdpr
696711 buttonLayout .setComponentAlignment (buttonGdpr , Alignment .BOTTOM_RIGHT );
697712 buttonLayout .setExpandRatio (buttonGdpr , 0 );
698713 UI .getCurrent ().addWindow (subWindowGdpR );
714+ subWindowGdpR .focus ();
699715 }
700716 }
701717}
0 commit comments