Add-on Directory

← Back

Tabs Extension

Tab sheet extension

Author

Rating

Popularity

<100

Tab sheet Extension

This addon extends the Vaadin 10 Tabs with a few additional features. This features may deprecate in future if the core provides similar functions.

Development instructions

Creating a common filter

The extension allows you to set a list of filterable components for a Tabs instance that should not fire a selection change event. With this feature you may add components, that the user can interact with and let them handle the selection manually.

String[] arrayOfTagNames = new String[] {"vaadin-button", "vaadin-text-field", ...};
TabsExtension.createFilterForTabs(tabs, arrayOfTagNames);

Disable tab selection via keyboard

This method is needed when you add writable components (like a text field) as part of you tabs or as a tab sheet component. Otherwise the tab sheet will select text matching tabs when you "type" the respective key.

TabsExtension.disableKeySelectionOfTabs(tabs);

Removing a modification

All TabExtension methods will return a Registration with that you may remove the changes from your element.

Registration registration = TabsExtension.createFilterForTabs(tabs, ...); // filter activated

registration.remove(); // after that call the filter will be deactivated

Closable tabs

The extension comes also with a implementation for closeable tabs. You may use them like other tabs, the only difference is, that the tab shows a close button, that will remove the tab from the tab sheet and handle the selection of a new tab.

You may style the tab as wanted. To style the button, just use the getButton() method of the tab.

CloseableTab closeableTab = new CloseableTab("Label");
closeableTab.addClassName("my-closeable-tab");
closeableTab.getButton().addClassName("my-closeable-button");

Sample code

Tabs tabs = new Tabs();
add(tabs);
IntStream.range(0, 10)
        .mapToObj(value -> new CloseableTab("Tab " + value))
        .forEach(tabs::add);

tabs.addSelectedChangeListener(event -> Notification.show("Selected " + tabs.getSelectedIndex()));

TabsExtension.createFilterForTabs(tabs, CloseableTab.TABS_FILTER);
TabsExtension.modifyKeyHandlerOfTabs(tabs, false, true);
Tabs tabs = new Tabs();
add(tabs);
tabs.addSelectedChangeListener(event -> Notification.show("Selected " + tabs.getSelectedIndex()));

HorizontalLayout layout = new HorizontalLayout();
TextField text = new TextField();
Button add = new Button("Add");
add.addClickListener(event -> {
    Tab tab = new Tab(text.getValue());
    tabs.add(tab);
    tabs.getElement().insertChild(tabs.getComponentCount() - 1, tab.getElement());
    tabs.setSelectedTab(tab); 
    text.clear();
});

layout.add(text, add);
tabs.add(layout);

TabsExtension.createFilterForTabs(tabs, "vaadin-text-field", "vaadin-button");
TabsExtension.modifyKeyHandlerOfTabs(tabs, true, false);

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Released
2018-08-14
Maturity
EXPERIMENTAL
License
Apache License 2.0

Compatibility

Framework
Vaadin 10
Browser
Browser Independent

Tabs Extension - Vaadin Add-on Directory

Tab sheet extension Tabs Extension - Vaadin Add-on Directory
# Tab sheet Extension This addon extends the Vaadin 10 Tabs with a few additional features. This features may deprecate in future if the core provides similar functions. ## Development instructions ### Creating a common filter The extension allows you to set a list of filterable components for a `Tabs` instance that should not fire a selection change event. With this feature you may add components, that the user can interact with and let them handle the selection manually. ``` String[] arrayOfTagNames = new String[] {"vaadin-button", "vaadin-text-field", ...}; TabsExtension.createFilterForTabs(tabs, arrayOfTagNames); ``` ### Disable tab selection via keyboard This method is needed when you add writable components (like a text field) as part of you tabs or as a tab sheet component. Otherwise the tab sheet will select text matching tabs when you "type" the respective key. ``` TabsExtension.disableKeySelectionOfTabs(tabs); ``` ### Removing a modification All TabExtension methods will return a Registration with that you may remove the changes from your element. ``` Registration registration = TabsExtension.createFilterForTabs(tabs, ...); // filter activated registration.remove(); // after that call the filter will be deactivated ``` ### Closable tabs The extension comes also with a implementation for closeable tabs. You may use them like other tabs, the only difference is, that the tab shows a close button, that will remove the tab from the tab sheet and handle the selection of a new tab. You may style the tab as wanted. To style the button, just use the `getButton()` method of the tab. ``` CloseableTab closeableTab = new CloseableTab("Label"); closeableTab.addClassName("my-closeable-tab"); closeableTab.getButton().addClassName("my-closeable-button"); ```
Source code (GitHub)
Demo (closeable tabs)

Tabs Extension version 0.0.1

Tabs Extension version 0.0.3
- fix for re-selecting tabs when the last tab is currently selected and closed (CloseableTab) - updated demo event output - updated readme

Tabs Extension version 0.0.4
- changed the visibility of the close method in CloseableTab to protected for extension.

Tabs Extension version 0.0.7

Online