Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The popover doesn't close on outside click if open on click is false #6691

Open
jcgueriaud1 opened this issue Oct 4, 2024 · 1 comment
Open
Assignees
Labels
documentation Improvements or additions to documentation vaadin-popover

Comments

@jcgueriaud1
Copy link
Contributor

Description

If I'm creating a Popover with:

        popover.setOpenOnClick(false);
        popover.setCloseOnOutsideClick(true);

The popover doesn't close on outside click.

Expected outcome

It should close.

Minimal reproducible example

package com.example.application.views;

import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.popover.Popover;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.select.Select;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.value.ValueChangeMode;
import com.vaadin.flow.router.Route;

@Route("popover-positioning")
public class PopoverPositioning extends VerticalLayout {

    public PopoverPositioning() {
        Popover popover1 = createPopover();
        Button button1 = new Button("Open popup 1", buttonClickEvent -> {
            if (popover1.isOpened()) {
                popover1.close();
            } else {
                popover1.open();
            }
        });
        popover1.setTarget(button1);
        Popover popover3 = createPopover();
        Button button2 = new Button("Open popup 2", buttonClickEvent -> {
            if (popover1.isOpened()) {
                popover1.close();
            } else {
                popover1.open();
            }
        });
        popover3.setTarget(button2);
        add(new HorizontalLayout(button1,button2, popover1, popover3));
        TextField searchField = new TextField("Search");
        searchField.setValueChangeMode(ValueChangeMode.EAGER);
        Popover popover = new Popover();
        popover.setTarget(searchField);
        popover.setOpenOnClick(false);
        popover.setCloseOnOutsideClick(true);
        Span span = new Span();
        popover.add(span);
        add(new HorizontalLayout(searchField, popover));
        searchField.addValueChangeListener(e -> {
            if (e.isFromClient()) {
                if (!popover.isOpened()) {
                    popover.open();
                }
                if (e.getValue() != null) {
                    span.setText("Searched:" + e.getValue().toString());
                } else {
                    span.setText("Searched");
                }
            }
        });

    }

    public Popover createPopover() {
        Popover popover = new Popover();
        popover.setOpenOnClick(false);
        popover.setCloseOnOutsideClick(true);
        popover.add(new Span("test"));
        Select<String> objectSelect = new Select<>();
        objectSelect.setItems("item 1", "item 2", "item 3");
        popover.add(objectSelect);
        return popover;
    }

}

Steps to reproduce

  • Fill some data in the TextField
  • See the popover
  • Click in the background
  • The popover is still opened.

Environment

Vaadin version(s): 24.5.0.beta5
OS: Mac

Browsers

No response

@web-padawan
Copy link
Member

This is kind of expected behavior as calling setOpenOnClick(false) without enabling any of the two other triggers using setOpenOnFocus(true) or setOpenOnHover(true) switches the Popover to the "manual mode", see WC logic.

In this mode, the Popover can be only opened and closed programmatically so setCloseOnOutsideClick(true) doesn't have any effect. I think we should document this (also for setCloseOnEsc() which works the same).

@web-padawan web-padawan added the documentation Improvements or additions to documentation label Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation vaadin-popover
Projects
None yet
Development

No branches or pull requests

2 participants