Skip to content

Commit

Permalink
feat: hide tabs if there is only one demo
Browse files Browse the repository at this point in the history
  • Loading branch information
javier-godoy authored and paodb committed Jul 15, 2024
1 parent 46bfb46 commit 30ab579
Showing 1 changed file with 18 additions and 0 deletions.
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

0 comments on commit 30ab579

Please sign in to comment.