Skip to content

Disabling and reenabling tabs in TabSheet loses "selected" attribute #8079

@WoozyG

Description

@WoozyG

Description

Individual Tab objects in a TabSheet component can be enabled/disabled dynamically. All tabs can be disabled, in fact, leaving none enabled. This continues to display the contents of the last selected tab, which I deem acceptable.

However, if you then re-enable one or more tabs, including the previously selected tab, the TabSheet reports that tab as selected, but even explicitly calling Tab.setSelected(true), which should set the "selected" attribute on the browser side DOM element, but it does not.

Further, re-enabling the selected tab should not require the developer to explicitly re-select the tab anyway, especially if the TabSheet still thinks that's the selected tab.

Expected outcome

TabSheet should both remember and properly display the selected tab as it is enabled and disabled.

Minimal reproducible example

TabSheet tabsheet = new TabSheet();

Tab tab1 = tabsheet.add("Tab one", new Div("ONE"));
Tab tab2 = tabsheet.add("Tab two", new Div("TWO"));
Tab tab3 = tabsheet.add("Tab three", new Div("THREE"));

NativeButton toggleEnabled =
new NativeButton("Toggle enabled",
event -> Stream.of(tab1, tab2, tab3).forEach(tab -> tab.setEnabled(!tab.isEnabled())));

NativeButton logSelectedIndex = new NativeButton("Log selected index",
event -> System.out.println("Selected index: " + tabsheet.getSelectedIndex()));

add(tabsheet, toggleEnabled, logSelectedIndex);

Steps to reproduce

see the submitted code, created from #7911 by Javier during an Expert Chat session :)

Environment

Vaadin version(s): 24 latest
OS: N/A

Browsers

Issue is not browser related

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions