Skip to content

Commit 19696cc

Browse files
mlopezFCjavier-godoy
authored andcommitted
fix: use event to close the drawer
1 parent 07bb7a1 commit 19696cc

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

src/main/java/com/flowingcode/addons/applayout/HasMenuItemCommands.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public default T setCommand(MouseButton button, Command command) {
5555
"mouseup",
5656
ev -> {
5757
command.execute();
58-
AppDrawer.findAppDrawer((Component) this).ifPresent(AppDrawer::close);
58+
((Component)this).getElement().executeJs("this.dispatchEvent(new CustomEvent('item-clicked', {bubbles: true}))");
5959
})
6060
.setFilter("event.button==" + button.ordinal());
6161
data.commands.put(button, Pair.of(command, registration));

src/test/java/com/flowingcode/addons/applayout/menu/PaperIconItem.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
*/
2020
package com.flowingcode.addons.applayout.menu;
2121

22-
import com.flowingcode.addons.applayout.AppDrawer;
22+
import java.util.Optional;
23+
2324
import com.vaadin.flow.component.Component;
2425
import com.vaadin.flow.component.HasComponents;
2526
import com.vaadin.flow.component.HasSize;
@@ -30,7 +31,6 @@
3031
import com.vaadin.flow.component.dependency.NpmPackage;
3132
import com.vaadin.flow.dom.Element;
3233
import com.vaadin.flow.server.Command;
33-
import java.util.Optional;
3434

3535
/**
3636
* Component that renders a paper-item
@@ -59,7 +59,7 @@ public void addCommand(Command command) {
5959
"click",
6060
e -> {
6161
command.execute();
62-
findAppDrawer(this).ifPresent(AppDrawer::close);
62+
((Component)this).getElement().executeJs("this.dispatchEvent(new CustomEvent('item-clicked', {bubbles: true}))");
6363
});
6464
}
6565
}
@@ -104,14 +104,4 @@ private Optional<Element> withIronIcon(boolean create) {
104104
}
105105
}
106106

107-
private static Optional<AppDrawer> findAppDrawer(Component component) {
108-
while (component != null) {
109-
if (component instanceof AppDrawer) {
110-
return Optional.of((AppDrawer) component);
111-
} else {
112-
component = component.getParent().orElse(null);
113-
}
114-
}
115-
return Optional.empty();
116-
}
117107
}

0 commit comments

Comments
 (0)