Skip to content

Commit 14e4654

Browse files
committed
Resolves #34 Make the menu list scrollable
1 parent 2a57e4d commit 14e4654

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
import java.util.List;
2727

2828
import com.flowingcode.addons.applayout.menu.MenuItem;
29+
import com.vaadin.flow.component.AttachEvent;
2930
import com.vaadin.flow.component.Component;
3031
import com.vaadin.flow.component.HasComponents;
3132
import com.vaadin.flow.component.Tag;
3233
import com.vaadin.flow.component.dependency.HtmlImport;
3334
import com.vaadin.flow.component.html.H4;
35+
import com.vaadin.flow.shared.Registration;
3436

3537
/**
3638
* Component that renders the app drawer
@@ -41,10 +43,11 @@
4143
@SuppressWarnings("serial")
4244
@Tag("app-drawer")
4345
@HtmlImport("bower_components/app-layout/app-drawer/app-drawer.html")
46+
@HtmlImport("bower_components/iron-scroll-target-behavior/iron-scroll-target-behavior.html")
4447
public class AppDrawer extends Component implements HasComponents {
4548

46-
private PaperListbox pm = new PaperListbox(Collections.emptyList());
47-
private Component header;
49+
private final PaperListbox pm = new PaperListbox(Collections.emptyList());
50+
private final Component header;
4851

4952
public AppDrawer(String title) {
5053
this(new H4(title));
@@ -57,8 +60,15 @@ public AppDrawer(Component headerComponent) {
5760
setSwipeOpen(true);
5861
this.add(headerComponent);
5962
this.add(pm);
63+
64+
Registration r[] = new Registration[1];
65+
r[0] = getElement().addEventListener("app-drawer-transitioned", ev->{
66+
//need to adjust the height after the drawer has been rendered
67+
getUI().ifPresent(ui->ui.getPage().executeJavaScript("$1.style.height='calc(100% - '+($0.scrollHeight+16)+'px)'", header, pm));
68+
r[0].remove();
69+
});
6070
}
61-
71+
6272
public void setSwipeOpen(boolean swipeOpen) {
6373
getElement().setAttribute("swipe-open", swipeOpen);
6474
}

src/main/resources/META-INF/resources/frontend/styles/applayout-styles.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
--app-drawer-scrim-background: rgba(0, 0, 100, 0.8);
5858
z-index: 1000;
5959
}
60+
61+
app-drawer paper-listbox {
62+
overflow-y: auto;
63+
}
6064

6165
</style>
6266
</custom-style>

src/test/java/com/flowingcode/addons/applayout/DemoView.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,20 @@ private MenuItem[] createMenuItems() {
197197
new MenuItem("SubMenu",
198198
new MenuItem("Hello Again",()->showContent("Hello Again!")),
199199
new MenuItem("And Again",()->showContent("And Again!")))
200-
)};
200+
),
201+
new MenuItem("Item 1"),
202+
new MenuItem("Item 2"),
203+
new MenuItem("Item 3"),
204+
new MenuItem("Item 4"),
205+
new MenuItem("Item 5"),
206+
new MenuItem("Item 6"),
207+
new MenuItem("Item 7"),
208+
new MenuItem("Item 8"),
209+
new MenuItem("Item 9"),
210+
new MenuItem("Item 10"),
211+
new MenuItem("Item 11"),
212+
new MenuItem("Item 12")
213+
};
201214
}
202215

203216
private void showContent(String content) {

0 commit comments

Comments
 (0)