From 9e2ddbe26fa46f5aa3d6819a125da54bb0ff6191 Mon Sep 17 00:00:00 2001
From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com>
Date: Wed, 12 Jun 2024 15:22:20 -0300
Subject: [PATCH 1/3] fix: add workaround for RouterLinks
Close #91
---
pom.xml | 2 +-
.../flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java | 8 +++++---
.../com/flowingcode/vaadin/addons/demo/TabbedDemo.java | 4 +---
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/pom.xml b/pom.xml
index fc1192f..fca4edf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -93,7 +93,7 @@
com.flowingcode.vaadin.addons
enhanced-tabs-addon
- 1.0.0
+ 1.0.1-SNAPSHOT
diff --git a/src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java b/src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java
index 4df0b45..65c09ba 100644
--- a/src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java
+++ b/src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java
@@ -42,7 +42,8 @@ public class EnhancedRouteTabs extends EnhancedTabs implements BeforeEnterObserv
private final Map routerLinkTabMap = new LinkedHashMap<>();
- public void add(RouterLink routerLink) {
+ public void add(String text, Class extends Component> target) {
+ RouterLink routerLink = super.addRouterLink(text, target);
routerLink.setHighlightCondition(HighlightConditions.sameLocation());
routerLink.setHighlightAction(
(link, shouldHighlight) -> {
@@ -50,8 +51,9 @@ public void add(RouterLink routerLink) {
setSelectedTab(routerLinkTabMap.get(routerLink));
}
});
- routerLinkTabMap.put(routerLink, new Tab(routerLink));
- add(routerLinkTabMap.get(routerLink));
+
+ Tab tab = getTabAt(getTabCount() - 1);
+ routerLinkTabMap.put(routerLink, tab);
}
@Override
diff --git a/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java b/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java
index d1d6ae2..f23faaa 100644
--- a/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java
+++ b/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java
@@ -39,7 +39,6 @@
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouterLayout;
-import com.vaadin.flow.router.RouterLink;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -152,8 +151,7 @@ public void addDemo(Class extends Component> clazz, String label) {
if (!clazz.isAnnotationPresent(Route.class)) {
throw new IllegalArgumentException(clazz + " must be annotated as Route");
}
- RouterLink tab = new RouterLink(label, clazz);
- tabs.add(tab);
+ tabs.add(label, clazz);
}
/**
From 45dfc9bcadd1f406cd2c0dfec86c0c2120ab00b0 Mon Sep 17 00:00:00 2001
From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com>
Date: Wed, 12 Jun 2024 15:24:18 -0300
Subject: [PATCH 2/3] refactor: make EnhancedRouteTabs a Composite
---
.../vaadin/addons/demo/EnhancedRouteTabs.java | 15 ++++++++++-----
.../vaadin/addons/demo/TabbedDemo.java | 1 -
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java b/src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java
index 65c09ba..36c3e5e 100644
--- a/src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java
+++ b/src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java
@@ -21,6 +21,7 @@
import com.flowingcode.vaadin.addons.enhancedtabs.EnhancedTabs;
import com.vaadin.flow.component.Component;
+import com.vaadin.flow.component.Composite;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.tabs.Tab;
import com.vaadin.flow.router.BeforeEnterEvent;
@@ -38,12 +39,12 @@
*
* @see https://cookbook.vaadin.com/tabs-with-routes/a
*/
-public class EnhancedRouteTabs extends EnhancedTabs implements BeforeEnterObserver {
+public class EnhancedRouteTabs extends Composite implements BeforeEnterObserver {
private final Map routerLinkTabMap = new LinkedHashMap<>();
public void add(String text, Class extends Component> target) {
- RouterLink routerLink = super.addRouterLink(text, target);
+ RouterLink routerLink = getContent().addRouterLink(text, target);
routerLink.setHighlightCondition(HighlightConditions.sameLocation());
routerLink.setHighlightAction(
(link, shouldHighlight) -> {
@@ -52,10 +53,14 @@ public void add(String text, Class extends Component> target) {
}
});
- Tab tab = getTabAt(getTabCount() - 1);
+ Tab tab = getContent().getTabAt(getContent().getTabCount() - 1);
routerLinkTabMap.put(routerLink, tab);
}
+ private void setSelectedTab(Tab tab) {
+ getContent().setSelectedTab(tab);
+ }
+
@Override
public void beforeEnter(BeforeEnterEvent event) {
setSelectedTab(null);
@@ -82,8 +87,8 @@ public RouterLink getFirstRoute() {
@Deprecated
public void addLegacyTab(String label, Component content) {
Tab tab = new Tab(label);
- add(tab);
- addSelectedChangeListener(
+ getContent().add(tab);
+ getContent().addSelectedChangeListener(
ev -> {
if (ev.getSelectedTab() == tab) {
TabbedDemo tabbedDemo = (TabbedDemo) getParent().get();
diff --git a/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java b/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java
index f23faaa..c6317e8 100644
--- a/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java
+++ b/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java
@@ -68,7 +68,6 @@ public TabbedDemo() {
demoHelperViewer = new DialogDemoHelperViewer();
tabs = new EnhancedRouteTabs();
- tabs.setWidthFull();
// Footer
orientationCB = new Checkbox("Toggle Orientation");
From cd3a172bdba8e8cacef560d61faed577e73f2a70 Mon Sep 17 00:00:00 2001
From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com>
Date: Wed, 12 Jun 2024 15:26:54 -0300
Subject: [PATCH 3/3] refactor: remove unused method
---
.../flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java b/src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java
index 36c3e5e..8f3b25c 100644
--- a/src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java
+++ b/src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java
@@ -74,11 +74,7 @@ public void beforeEnter(BeforeEnterEvent event) {
}
}
- public Map getRouterLinkTabMap() {
- return routerLinkTabMap;
- }
-
- public RouterLink getFirstRoute() {
+ private RouterLink getFirstRoute() {
Optional first =
routerLinkTabMap.entrySet().stream().map(Map.Entry::getKey).findFirst();
return first.isPresent() ? first.get() : null;