如何防止上下文菜单关闭?

How to prevent ContextMenu from closing?

我想将 TextField 作为组件添加到 MenuItem。它有效,但只要我单击该字段,ContextMenu 就会收到 DetachEvent 并关闭。当我单击其中一个 MenuItem 时,有没有办法防止 ContextMenu 分离?

Button btnFilter = createFilterButton();
ContextMenu cm = new ContextMenu();
cm.setOpenOnClick(true);
cm.setTarget(btnFilter);
TextField tf = new TextField();
MenuItem mi = cm.addItem(tf, e->{});

通过调用方法 add() 而不是 addItem()

解决了这个问题
Button btnFilter = createFilterButton();
ContextMenu cm = new ContextMenu();
cm.setOpenOnClick(true);
cm.setTarget(btnFilter);
TextField tf = new TextField();
tf.addValueChangeListener(e -> {...});
cm.add(tf);