File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed
vaadin-popover-flow-parent/vaadin-popover-flow/src
main/java/com/vaadin/flow/component/popover
test/java/com/vaadin/flow/component/popover Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 2323import com .vaadin .flow .component .Component ;
2424import com .vaadin .flow .component .ComponentEvent ;
2525import com .vaadin .flow .component .ComponentEventListener ;
26- import com .vaadin .flow .component .DomEvent ;
2726import com .vaadin .flow .component .HasAriaLabel ;
2827import com .vaadin .flow .component .HasComponents ;
2928import com .vaadin .flow .component .Synchronize ;
@@ -78,6 +77,9 @@ public Popover() {
7877
7978 updateTrigger ();
8079 setRole ("dialog" );
80+
81+ getElement ().addPropertyChangeListener ("opened" , event -> fireEvent (
82+ new OpenedChangeEvent (this , event .isUserOriginated ())));
8183 }
8284
8385 /**
@@ -177,7 +179,6 @@ private static void applyConfigurationForUI(UI ui) {
177179 * {@code opened-changed} event is sent when the popover opened state
178180 * changes.
179181 */
180- @ DomEvent ("opened-changed" )
181182 public static class OpenedChangeEvent extends ComponentEvent <Popover > {
182183 private final boolean opened ;
183184
@@ -200,7 +201,6 @@ public boolean isOpened() {
200201 public void setOpened (boolean opened ) {
201202 if (opened != isOpened ()) {
202203 getElement ().setProperty ("opened" , opened );
203- fireEvent (new OpenedChangeEvent (this , false ));
204204 }
205205 }
206206
Original file line number Diff line number Diff line change 2525
2626import com .vaadin .flow .component .ComponentEventListener ;
2727import com .vaadin .flow .component .UI ;
28+ import com .vaadin .flow .dom .DomEvent ;
29+ import com .vaadin .flow .dom .Element ;
30+ import com .vaadin .flow .internal .JacksonUtils ;
31+ import com .vaadin .flow .internal .nodefeature .ElementListenerMap ;
2832import com .vaadin .flow .server .VaadinSession ;
2933
3034public class PopoverOpenedChangeListenerTest {
@@ -87,6 +91,19 @@ public void close() {
8791 assertListenerCalls (0 );
8892 }
8993
94+ @ Test
95+ public void openedChangeFromClient_noChangeEvent () {
96+ Element element = popover .getElement ();
97+ element .getNode ().getFeature (ElementListenerMap .class )
98+ .fireEvent (new DomEvent (element , "opened-changed" ,
99+ JacksonUtils .createObjectNode ()));
100+
101+ // The event should only be fired when the opened state changes, not for
102+ // any opened-changed event from the client
103+ Assert .assertNull (event .get ());
104+ assertListenerCalls (0 );
105+ }
106+
90107 private void assertListenerCalls (int expectedCount ) {
91108 Mockito .verify (mockListener , Mockito .times (expectedCount ))
92109 .onComponentEvent (Mockito .any ());
You can’t perform that action at this time.
0 commit comments