Skip to content

Commit 30ab579

Browse files
javier-godoypaodb
authored andcommitted
feat: hide tabs if there is only one demo
1 parent 46bfb46 commit 30ab579

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class TabbedDemo extends VerticalLayout implements RouterLayout {
5353
private static final Logger logger = LoggerFactory.getLogger(TabbedDemo.class);
5454

5555
private static final int MOBILE_DEVICE_BREAKPOINT_WIDTH = 768;
56+
private boolean autoVisibility;
5657
private EnhancedRouteTabs tabs;
5758
private HorizontalLayout footer;
5859
private SplitLayoutDemo currentLayout;
@@ -138,6 +139,7 @@ public void addDemo(Component demo) {
138139
@Deprecated
139140
public void addDemo(Component demo, String label, String sourceCodeUrl) {
140141
tabs.addLegacyTab(label, demo);
142+
updateVisibility();
141143
}
142144

143145
/**
@@ -151,6 +153,22 @@ public void addDemo(Class<? extends Component> clazz, String label) {
151153
throw new IllegalArgumentException(clazz + " must be annotated as Route");
152154
}
153155
tabs.add(label, clazz);
156+
updateVisibility();
157+
}
158+
159+
private void updateVisibility() {
160+
if (autoVisibility) {
161+
tabs.setVisible(tabs.getContent().getTabCount() > 1);
162+
}
163+
}
164+
165+
/**
166+
* Sets the autovisibility mode. When autovisibility is enabled, the tabs component is hidden
167+
* unless it contains two or more tabs.
168+
*/
169+
public void setAutoVisibility(boolean autoVisibility) {
170+
this.autoVisibility = autoVisibility;
171+
updateVisibility();
154172
}
155173

156174
/**

0 commit comments

Comments
 (0)