Afaik these 2 lines should be basically equivalent. setProperty should work for this. If it doesn’t, but executeJs does then I think it might be some timing issue since afaik executeJs calls are executed later.
You probably also want to make sure that the opened property is synchronized to the server too so that if it changes on the client, you also get the new state of it on the server.
Actually that might be the problem that server still thinks that opened is false (if the opening was triggered from client side and not from Java code). In that case setProperty("opened", false) would not do anything if server thinks that it is already false.
This part is about that https://vaadin.com/docs/v14/flow/web-components/creating-java-api-for-a-web-component.html#synchronizing-the-value but the relevant part for this case is actually a bit hidden since here we don’t care about a “value” property but another property (opened). If we were interested in the “value” property and were extending AbstractSinglePropertyField like suggested then the value property synchronization would be handled automatically, but for other properties you still need to set up the synchronization. The relevant part here is the last “NOTE” block on gray background:
Some web components also update other properties that are not related to HasValue. [Creating A Simple Component Using the Element API]
(https://vaadin.com/docs/v14/flow/creating-components/tutorial-component-basic.html) describes how you can use the @Synchronize annotation to synchronize property values without automatically firing a value change event.