|
2 | 2 | * #%L
|
3 | 3 | * Enhanced Tabs Add-on
|
4 | 4 | * %%
|
5 |
| - * Copyright (C) 2023 Flowing Code |
| 5 | + * Copyright (C) 2023-2024 Flowing Code |
6 | 6 | * %%
|
7 | 7 | * Licensed under the Apache License, Version 2.0 (the "License");
|
8 | 8 | * you may not use this file except in compliance with the License.
|
|
41 | 41 | import com.vaadin.flow.component.HasEnabled;
|
42 | 42 | import com.vaadin.flow.component.HasSize;
|
43 | 43 | import com.vaadin.flow.component.HasStyle;
|
| 44 | +import com.vaadin.flow.component.UI; |
44 | 45 | import com.vaadin.flow.component.contextmenu.MenuItem;
|
45 | 46 | import com.vaadin.flow.component.dependency.CssImport;
|
46 | 47 | import com.vaadin.flow.component.dependency.JsModule;
|
47 | 48 | import com.vaadin.flow.component.menubar.MenuBar;
|
48 | 49 | import com.vaadin.flow.component.tabs.Tab;
|
| 50 | +import com.vaadin.flow.router.RouterLink; |
49 | 51 | import com.vaadin.flow.shared.Registration;
|
50 | 52 | import java.io.Serializable;
|
51 | 53 | import java.util.ArrayList;
|
@@ -196,6 +198,22 @@ public void add(Tab... tabs) {
|
196 | 198 | }
|
197 | 199 | }
|
198 | 200 |
|
| 201 | + public RouterLink addRouterLink(String text, Class<? extends Component> target) { |
| 202 | + RouterLink routerLink = new RouterLink(text, target); |
| 203 | + routerLink.getElement().executeJs( |
| 204 | + "this.addEventListener('click', e => {\n"+ |
| 205 | + "e.preventDefault();\n"+ |
| 206 | + "this.dispatchEvent(new CustomEvent('client-side-click'));\n"+ |
| 207 | + "});\n"); |
| 208 | + |
| 209 | + routerLink.getElement().addEventListener("client-side-click", event -> { |
| 210 | + UI.getCurrent().navigate(target); |
| 211 | + }); |
| 212 | + |
| 213 | + add(new Tab(routerLink)); |
| 214 | + return routerLink; |
| 215 | + } |
| 216 | + |
199 | 217 | /**
|
200 | 218 | * Removes the given child tabs from this component.
|
201 | 219 | *
|
|
0 commit comments