Here, the user is trying to save while the value in acustom dropdown field is incomplete:
The field shows its dropdown panel ( an anchored Popover ) and my validation routine displays an error ( a Notification )
Due to the z-indexes, the Notification is behind the Popover.
In this case the Popover is 1001 and the Notification is 201.
Is there anything I can do to influence this?
Actually, I’m having trouble seeing a consistent pattern.
The snippet above was from yesterday. When I try to reproduce today, the popover gets z-index 1001 and the notification-container has none.
But, as long as vaadin might set the z-index in the tag style, I can’t reliably override in the css
This worked, but only if Vaadin had set a z-index on the vaadin-notification-container tag!
If there was nothing on the tag, my notification still ended up behind the popover…
So, I assume Vaadin does stuff with the z-index in javascript?
The overlay has z-index: 200 by default and notification container has z-index: 1000 which should be actually removed as it’s a leftover from the old logic where notification had a fixed value (this also applied e.g. to Tooltip - it used to have z-index: 1100 in the past).
As a workaround you can try to execute bringToFront() on the vaadin-notification-container element (this logic runs every time a new notification is being shown).
I’ve reverted the code from my actual application so I can’t test that.
However, I’ve created a simple test-view:
package com.ec.traveller;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.notification.NotificationVariant;
import com.vaadin.flow.component.notification.Notification.Position;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;
@Route("testZindex")
public class TestZIndex extends VerticalLayout {
public TestZIndex() {
add(
new Button("Open Dialog + Notification", event -> {
openDialog();
openNotification();
})
,
new Button("Open Notification + Dialog", event -> {
openNotification();
openDialog();
})
);
}
private void openDialog() {
var dialog = new Dialog("Dialog");
dialog.setModal(false);
dialog.setDraggable(true);
dialog.getFooter().add(new Button("OK", event -> dialog.close()));
dialog.open();
}
private void openNotification() {
var notification = new Notification("Notification");
notification.addThemeVariants(NotificationVariant.LUMO_ERROR);
notification.setPosition(Position.MIDDLE);
notification.setDuration(0);
notification.add(new Button("OK", event -> notification.close()));
notification.open();
}
}
The fun thing is that this works as I’d like right out of the box;
The z-order is based on the order in which the Notification / Dialogs are opened
If I drag a Dialog, it is moved to the top
The only thing that was unexpected is that if I have multiple notifications they all have the same z-index, since they share the same vaadin-notification-container, while the Dialogs each have their own.
So, I don’t know why it behaved the way it did in my main application, but it looks like I should be able to control it with the order in which I open them
Yes, this is exactly how it is supposed to work. Interacting with a modeless dialog does bring it to front automatically. Also notifications indeed share a single container so showing a new notification makes old notifications also appear on top of other overlays.