Navigation
Tab
A single tab within a nana-tab-group. Place tabs in the group's nav slot and link each to a panel via the panel attribute. The host element is the focusable tab (role="tab"), so assistive tech and the group's roving-tabindex navigation operate on a single element.
In Svelte this is NanaTab, installed with the tabs. See Tab Group.
Preview
Section titled “Preview”<nana-tab-group variant="segmented" style="width: 100%">
<nana-tab slot="nav" panel="a">Overview</nana-tab>
<nana-tab slot="nav" panel="b">Activity</nana-tab>
<nana-tab-panel name="a">Overview panel.</nana-tab-panel>
<nana-tab-panel name="b">Activity panel.</nana-tab-panel>
</nana-tab-group> Installation
Section titled “Installation”npm install @nana-tec/ui-componentsImport
Section titled “Import”
Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and
each component downloads only the first time a page uses it:
import "@nana-tec/ui-components/autoloader";import "@nana-tec/ui-components/theme";The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.
Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:
import "@nana-tec/ui-components/tab";
Copied in with npx @nana-tec/ui add tab? Import your project's own
@/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.
Basic usage
Section titled “Basic usage”<nana-tab-group style="width:100%"> <nana-tab slot="nav" panel="a">Tab</nana-tab> <nana-tab-panel name="a">Panel.</nana-tab-panel></nana-tab-group>Icons & counts
Section titled “Icons & counts”Add a count badge to a tab.
<nana-tab-group style="width: 100%">
<nana-tab slot="nav" panel="inbox" count="12">Inbox</nana-tab>
<nana-tab slot="nav" panel="drafts" count="3">Drafts</nana-tab>
<nana-tab-panel name="inbox">Inbox panel.</nana-tab-panel>
<nana-tab-panel name="drafts">Drafts panel.</nana-tab-panel>
</nana-tab-group> Closable
Section titled “Closable”Add closable to show a close button on a tab.
<nana-tab-group style="width: 100%">
<nana-tab slot="nav" panel="a">Overview</nana-tab>
<nana-tab slot="nav" panel="settings" closable>Settings</nana-tab>
<nana-tab-panel name="a">Overview panel.</nana-tab-panel>
<nana-tab-panel name="settings">Settings panel.</nana-tab-panel>
</nana-tab-group> Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
active | active | boolean | false | Whether the tab is the active/selected one (managed by the group). |
closable | closable | boolean | false | Show a close button. |
count | count | string | number | undefined | — | Optional count shown as a small badge after the label. |
disabled | disabled | boolean | false | Disable the tab. |
panel | panel | string | '' | The name of the panel this tab controls (matches a panel's name). |
size | size | TabSize | 'md' | Tab size. Usually set automatically by the parent nana-tab-group. |
variant | variant | TabVariant | 'underline' | Visual style. Usually set automatically by the parent nana-tab-group. |
Events
| Event | Description |
|---|---|
nana-tab-close | Emitted when the tab is closed via the button or Delete / Backspace (detail.panel). |
Slots
| Slot | Description |
|---|---|
(default) | The tab's label. |
prefix | Content before the label, typically an icon. |
suffix | Content after the label, e.g. a count badge. |
CSS parts
| Part | Description |
|---|---|
::part(base) | The tab's inner container. |
::part(count) | The built-in count badge. |
::part(close-button) | The close button (when closable). |
CSS custom properties
| Property | Description |
|---|---|
--nana-tab-hover-bg | Hover fill for the pill, filled and ghost variants. Defaults to a translucent tint of the text colour, so it reads on any surface; set an opaque colour to pin it. |
--nana-tab-active-bg | Fill of the active thumb in the segmented variant. |
--nana-tab-thumb-bg | Theme slot for the segmented thumb fill, set by the light and dark themes. |
--nana-tab-thumb-line | Theme slot for the segmented thumb edge. |
--nana-tab-inactive-color | Label colour of an unselected tab. Defaults to the muted text step, which clears 4.5:1 on the segmented track; check contrast before recessing it further. |
--nana-tab-group-track-pad | Read from the group so the active thumb stays concentric with the track |
--nana-tab-group-track-radius | Read from the group so the active thumb stays concentric with the track |