PopupView

Live Demo

The PopupView component allows opening a pop-up view either by clicking on a link or programmatically. The component has two representations: a minimized textual representation and the popped-up content. The view can contain any components. The view closes automatically when the mouse pointer moves outside the view.

In the following, we have a popup view with a text field and a button that opens automatically when the user clicks on a “Open the popup” link:

Java

  1. // Content for the PopupView
  2. VerticalLayout popupContent = new VerticalLayout();
  3. popupContent.addComponent(new TextField("Textfield"));
  4. popupContent.addComponent(new Button("Button"));
  5. // The component itself
  6. PopupView popup = new PopupView("Pop it up", popupContent);
  7. layout.addComponent(popup);

If the textual minimized representation is not given (a null is given), the component is invisible in the minimized state. The pop-up can be opened programmatically by calling setPopupVisible(true). For example:

Java

  1. // A pop-up view without minimalized representation
  2. PopupView popup = new PopupView(null, myComponent);
  3. // A component to open the view
  4. Button button = new Button("Show details", click ->
  5. popup.setPopupVisible(true));
  6. layout.addComponents(button, popup);

When the pop-up is opened or closed, a PopupVisibilityEvent is fired, which can be handled with a PopupVisibilityListener added with setPopupVisibilityListener().

Java

  1. // Fill the pop-up content when it's popped up
  2. popup.addPopupVisibilityListener(event -> {
  3. if (event.isPopupVisible()) {
  4. popupContent.removeAllComponents();
  5. popupContent.addComponent(new Table(null,
  6. TableExample.generateContent()));
  7. }});

CSS Style Rules

CSS

  1. .v-popupview {}
  2. .v-overlay-container {
  3. .v-popupview-popup {
  4. .popupContent { }
  5. }
  6. }

In minimalized state, the component has v-popupview style. When popped up, the pop-up content is shown in a v-popupview-popup overlay element under the v-overlay-container, which is contains all floating overlays outside the component hierarchy.