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

feat: hide tabs if there is only one demo #105

Merged
merged 1 commit into from
Jul 15, 2024
Merged
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
18 changes: 18 additions & 0 deletions src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class TabbedDemo extends VerticalLayout implements RouterLayout {
private static final Logger logger = LoggerFactory.getLogger(TabbedDemo.class);

private static final int MOBILE_DEVICE_BREAKPOINT_WIDTH = 768;
private boolean autoVisibility;
private EnhancedRouteTabs tabs;
private HorizontalLayout footer;
private SplitLayoutDemo currentLayout;
Expand Down Expand Up @@ -138,6 +139,7 @@ public void addDemo(Component demo) {
@Deprecated
public void addDemo(Component demo, String label, String sourceCodeUrl) {
tabs.addLegacyTab(label, demo);
updateVisibility();
}

/**
Expand All @@ -151,6 +153,22 @@ public void addDemo(Class<? extends Component> clazz, String label) {
throw new IllegalArgumentException(clazz + " must be annotated as Route");
}
tabs.add(label, clazz);
updateVisibility();
}

private void updateVisibility() {
if (autoVisibility) {
tabs.setVisible(tabs.getContent().getTabCount() > 1);
}
}

/**
* Sets the autovisibility mode. When autovisibility is enabled, the tabs component is hidden
* unless it contains two or more tabs.
*/
public void setAutoVisibility(boolean autoVisibility) {
this.autoVisibility = autoVisibility;
updateVisibility();
}

/**
Expand Down
Loading