Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add workaround for RouterLinks in EnhancedRouteTabs #90

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,19 @@ public class EnhancedRouteTabs extends EnhancedTabs implements BeforeEnterObserv

private final Map<RouterLink, Tab> routerLinkTabMap = new LinkedHashMap<>();

public void add(RouterLink routerLink) {
public void addRouterLink(String label, Class<? extends Component> target) {
RouterLink routerLink = new RouterLink(label, target);
routerLink.getElement().executeJs("""
this.addEventListener("click", e => {
e.preventDefault();
this.dispatchEvent(new CustomEvent('client-side-click'));
});
""");

routerLink.getElement().addEventListener("client-side-click", event -> {
UI.getCurrent().navigate(target);
});

routerLink.setHighlightCondition(HighlightConditions.sameLocation());
routerLink.setHighlightAction(
(link, shouldHighlight) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.addRouterLink(label, clazz);
}

/**
Expand Down
Loading