Primitives
Dynamically show and hide content based on an active tab.
Import the Tabs primitives from ng-primitives/tabs
.
import { NgpTabset, NgpTabList, NgpTabButton, NgpTabPanel } from 'ng-primitives/tabs';
Assemble the tabs directives in your template.
<div ngpTabset>
<div ngpTabList>
<button ngpTabButton ngpTabButtonValue="tab1">Tab 1</button>
<button ngpTabButton ngpTabButtonValue="tab2">Tab 2</button>
<button ngpTabButton ngpTabButtonValue="tab3">Tab 3</button>
</div>
<div ngpTabPanel ngpTabPanelValue="tab1">Tab 1 content</div>
<div ngpTabPanel ngpTabPanelValue="tab2">Tab 2 content</div>
<div ngpTabPanel ngpTabPanelValue="tab3">Tab 3 content</div>
</div>
The following directives are available to import from the ng-primitives/tabs
package:
Apply the ngpTabset
directive to an element to manage the tabs.
[ngpTabset]
ngpTabset
The following data attributes are applied to the ngpTabset
directive:
Attribute | Description | Value |
---|---|---|
data-orientation |
The orientation of the tabs. | horizontal | vertical |
Apply the ngpTabList
directive to an element that represents the list of tab buttons.
[ngpTabList]
ngpTabList
The following data attributes are applied to the ngpTabList
directive:
Attribute | Description | Value |
---|---|---|
data-orientation |
The orientation of the tabs. | horizontal | vertical |
Apply the ngpTabButton
directive to an element within a tab list to represent a tab button. This directive should be applied to a button element.
[ngpTabButton]
ngpTabButton
The following data attributes are applied to the ngpTabButton
directive:
Attribute | Description | Value |
---|---|---|
data-orientation |
The orientation of the tabs. | horizontal | vertical |
data-active |
Applied when the tab is active. | - |
data-disabled |
Applied when the tab is disabled. | - |
data-hover |
Applied when the tab is hovered. | - |
data-focus-visible |
Applied when the tab is focused. | - |
data-press |
Applied when the tab is pressed. | - |
Apply the ngpTabPanel
directive to an element that represents the content of a tab.
[ngpTabPanel]
ngpTabPanel
The following data attributes are applied to the ngpTabPanel
directive:
Attribute | Description | Value |
---|---|---|
data-active |
Applied when the tab is active. | - |
data-orientation |
The orientation of the tabs. | horizontal | vertical |
You can configure the default options for all tabss in your application by using the provideNgpTabsConfig
function in a providers array.
import { provideNgpTabsConfig } from 'ng-primitives/tabs';
bootstrapApplication(AppComponent, {
providers: [
provideNgpTabsConfig({
orientation: 'horizontal',
activateOnFocus: false,
wrap: false,
}),
],
});
The following options are available to configure the default tab options:
Adheres to the Tabs WAI-ARIA design pattern.
Copyright © 2024 Angular Primitives