Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vaadin Accordion with Button in summary

In my Vaadin 14 app, I want to add an Accordion component that has several components in its summary (which is always displayed), among which a Button. Clicking in the summary normally toggles the display of the AccordionPanel content. How can I prevent the AccordionPanel to collapse/expand when the button in the summary is clicked?

Objects are created simply as follows:

Accordion accordion = new Accordion();

MyPanel panel = new MyPanel();

accordion.add(panel);

with MyPanel constructor simply calling setSummary() with a layout containing the button.

like image 241
herman Avatar asked Dec 06 '25 13:12

herman


1 Answers

I found the answer in this thread on the forum.

It turns out you can prevent the propagation of the button click with this hack:

button.getElement().addEventListener("click", click -> {
        //do nothing
}).addEventData("event.stopPropagation()");

This seems like a core functionality that the framework should provide out of the box, but this ticket is still open.

like image 56
herman Avatar answered Dec 08 '25 10:12

herman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!