How to include a click-listener onto tabs? Not change-listener

Hi!

I wonder if there is a working example for a click listener for tabs? The current code I’m using is a change-listener. But I want to have a click listener instead.

Is that possible?

According to the [documentation]
(https://vaadin.com/docs/v14/flow/element-api/tutorial-event-listener.html), yes that is possible. You can add Listeners to any kind of event by using the element API.

Tab someTab = new Tab("hello");
someTab.getElement().addEventListener("click", event -> {
    // do what you gotta do 
});

Yes, you can add listeners to any type of event fired in the browser through the Element. Just specify the name of the event:

        Tabs tabs = new Tabs();
        Tab tab = new Tab("Foo");
        Tab tab2 = new Tab("Bar");
        tab.getElement().addEventListener("click", e -> {
           Notification.show(tab.getLabel());
        });

        tabs.add(tab, tab2);

EDIT: Ooops, Kaspar beat me to it.

Kaspar Scherrer:
According to the [documentation]
(https://vaadin.com/docs/v14/flow/element-api/tutorial-event-listener.html), yes that is possible. You can add Listeners to any kind of event by using the element API.

Tab someTab = new Tab("hello");
someTab.getElement().addEventListener("click", event -> {
    // do what you gotta do 
});

Thank you very much. That’s helped me. :slight_smile:

Olli Tietäväinen:
Yes, you can add listeners to any type of event fired in the browser through the Element. Just specify the name of the event:

        Tabs tabs = new Tabs();
        Tab tab = new Tab("Foo");
        Tab tab2 = new Tab("Bar");
        tab.getElement().addEventListener("click", e -> {
           Notification.show(tab.getLabel());
        });

        tabs.add(tab, tab2);

EDIT: Ooops, Kaspar beat me to it.

Tackar så mycket! Detta hjälpte mig :slight_smile: