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..8f3b25c 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,11 +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(RouterLink routerLink) { + public void add(String text, Class target) { + RouterLink routerLink = getContent().addRouterLink(text, target); routerLink.setHighlightCondition(HighlightConditions.sameLocation()); routerLink.setHighlightAction( (link, shouldHighlight) -> { @@ -50,8 +52,13 @@ public void add(RouterLink routerLink) { setSelectedTab(routerLinkTabMap.get(routerLink)); } }); - routerLinkTabMap.put(routerLink, new Tab(routerLink)); - add(routerLinkTabMap.get(routerLink)); + + Tab tab = getContent().getTabAt(getContent().getTabCount() - 1); + routerLinkTabMap.put(routerLink, tab); + } + + private void setSelectedTab(Tab tab) { + getContent().setSelectedTab(tab); } @Override @@ -67,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; @@ -80,8 +83,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 d1d6ae2..c6317e8 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; @@ -69,7 +68,6 @@ public TabbedDemo() { demoHelperViewer = new DialogDemoHelperViewer(); tabs = new EnhancedRouteTabs(); - tabs.setWidthFull(); // Footer orientationCB = new Checkbox("Toggle Orientation"); @@ -152,8 +150,7 @@ public void addDemo(Class 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); } /**