Skip to content

Commit bee35c7

Browse files
committed
Use executeJs instead of execute JavaScript
1 parent 6bb662f commit bee35c7

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public AppDrawer(Component headerComponent) {
6363
Registration[] r = new Registration[1];
6464
r[0] = getElement().addEventListener("app-drawer-transitioned", ev->{
6565
//need to adjust the height after the drawer has been rendered
66-
getUI().ifPresent(ui->ui.getPage().executeJavaScript("$1.style.height='calc(100% - '+($0.scrollHeight+16)+'px)'", header, pm));
66+
pm.getElement().executeJs("this.style.height='calc(100% - '+($0.scrollHeight+16)+'px)'", header);
6767
r[0].remove();
6868
});
6969
}
@@ -116,5 +116,8 @@ private CollapseButton collectMenus(MenuItem topMenuItem) {
116116
collapseButton.setEnabled(topMenuItem.isEnabled());
117117
return collapseButton;
118118
}
119-
119+
120+
void toggle() {
121+
this.getElement().executeJs("this.toggle()");
122+
}
120123
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222

2323
import java.net.URL;
24+
import java.util.Optional;
2425

2526
import com.vaadin.flow.component.Component;
2627
import com.vaadin.flow.component.HasComponents;
@@ -84,8 +85,7 @@ private PaperIconItem(String title, String icon, URL image, Command command, App
8485
if (command!=null) {
8586
this.getElement().addEventListener("click", e->{
8687
command.execute();
87-
if (appDrawer!=null)
88-
appDrawer.getUI().ifPresent(ui->ui.getPage().executeJavaScript("" + appDrawer.getId().get() + ".toggle()"));
88+
Optional.ofNullable(appDrawer).ifPresent(AppDrawer::toggle);
8989
});
9090
}
9191
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222

2323

24+
import java.util.Optional;
25+
2426
import com.vaadin.flow.component.Component;
2527
import com.vaadin.flow.component.HasEnabled;
2628
import com.vaadin.flow.component.HasSize;
@@ -53,8 +55,9 @@ public PaperItem(String title, Command command, AppDrawer appDrawer) {
5355
if (command!=null) {
5456
this.getElement().addEventListener("click", e->{
5557
command.execute();
58+
Optional.ofNullable(appDrawer).ifPresent(AppDrawer::toggle);
5659
if (appDrawer!=null)
57-
appDrawer.getUI().ifPresent(ui->ui.getPage().executeJavaScript("" + appDrawer.getId().get() + ".toggle()"));
60+
appDrawer.getElement().executeJs("this.toggle()");
5861
});
5962
}
6063
}

0 commit comments

Comments
 (0)