flow-components icon indicating copy to clipboard operation
flow-components copied to clipboard

TabSheet internal tabs customization

Open gschrader opened this issue 1 year ago • 10 comments

Describe your motivation

I wanted to be able to set the tabs orientation to vertical.

Describe the solution you'd like

maybe add a method to allow to customize the tabs instance in case further methods become available:

In the class TabSheet:

    public void customizeTabs(Consumer<Tabs> tabsConsumer) {
        tabsConsumer.accept(tabs);
    }

my usage to set vertical orientation would be

            tabSheet.customizeTabs(tabs -> {
                tabs.setOrientation(Tabs.Orientation.VERTICAL);
            });

Describe alternatives you've considered

I'm using reflection for now 🤮:

            Field field = TabSheet.class.getDeclaredField("tabs");
            field.setAccessible(true);
            Tabs tabs = (Tabs) field.get(tabSheet);
            tabs.setOrientation(Tabs.Orientation.VERTICAL);

Additional context

No response

gschrader avatar Jul 06 '23 19:07 gschrader

We could consider exposing Tabs directly as a getter.

yuriy-fix avatar Jul 12 '23 12:07 yuriy-fix

Yeah a getter would work, I'm not sure why I didn't just propose that.

gschrader avatar Jul 13 '23 15:07 gschrader

There is an alternative TabSheet component in Directory which has a feature of vertical Tabs https://vaadin.com/directory/component/tabsheet

TatuLund avatar Jul 13 '23 17:07 TatuLund

I would prefer to stick with the official component for easier upgrades down the road.

gschrader avatar Jul 13 '23 18:07 gschrader

Additional context: https://github.com/vaadin/flow-components/issues/5370

yuriy-fix avatar Aug 23 '23 12:08 yuriy-fix

I'm not sure if exposing Tabs in TabSheet is a good idea. Giving the user full control over the internal component may lead to unexpected results.

For example, with the following TabSheet:

Screenshot 2023-08-31 at 12 03 02

var tabsheet = new TabSheet();
tabsheet.setPrefixComponent(new Span("Prefix"));
tabsheet.setSuffixComponent(new Span("Suffix"));
tabsheet.add("Tab one", new Span("Tab one content"));
tabsheet.add("Tab two", new Span("Tab two content"));
add(tabsheet);

If you try to make the Tabs vertical with tabsheet.getTabs().setOrientation(Orientation.VERTICAL); (as implemented by https://github.com/vaadin/flow-components/pull/5408) you'd end up with:

Screenshot 2023-08-31 at 12 03 17

...which is probably not what you wanted here.

Vertical TabSheet should probably look more like this (needs better design of course):

Screenshot 2023-08-31 at 12 08 33

tomivirkki avatar Aug 31 '23 09:08 tomivirkki

@tomivirkki you're right, I knew something didn't look quite right but it took your screenshots for me to realize. I have since gone with a different layout so I'm not sure what you want to do with this open issue.

gschrader avatar Aug 31 '23 15:08 gschrader

I also would like to see TabSheet with vertical orientation. Like gschrader I also do not want to install components from Directory and not being part of Vaadin Flow.

Avec112 avatar Feb 27 '24 09:02 Avec112

...which is probably not what you wanted here.

Easy workaround:


vaadin-tabsheet {
  flex-direction: row;
}

knoobie avatar Apr 04 '24 11:04 knoobie

This allows me to set up the TabSheet vertically.

        final TabSheet tabSheet = new TabSheet();
        tabSheet.addClassNames(LumoUtility.Display.FLEX, LumoUtility.FlexDirection.ROW);

        Tabs tabs = (Tabs) tabSheet.getChildren()
                .filter(c -> c.getClass().equals(Tabs.class))
                .findFirst().orElse(null);

        if (tabs != null) {
            tabs.getElement().setAttribute("orientation", "vertical");
        }

fredpena avatar Sep 02 '24 02:09 fredpena