▚TabSelect
Horizontal tab-based selection component with descriptions and scroll support. The component must be focused to receive keyboard input.
Home
Files
Settings
Plugins
────────────────────────────────────────────────
panel Dashboard and overview
event focus() — awaiting keys
##Renderable API
1import { TabSelectRenderable, TabSelectRenderableEvents, createCliRenderer } from "@opentui/core"23const renderer = await createCliRenderer()45const tabs = new TabSelectRenderable(renderer, {6id: "tabs",7width: 60,8options: [9 { name: "Home", description: "Dashboard and overview" },10 { name: "Files", description: "File management" },11 { name: "Settings", description: "Application settings" },12],13tabWidth: 20,14})1516tabs.on(TabSelectRenderableEvents.ITEM_SELECTED, (index, option) => {17console.log("Tab:", option.name)18})1920tabs.focus()21renderer.root.add(tabs)
##Construct API
1import { TabSelect, createCliRenderer } from "@opentui/core"23const renderer = await createCliRenderer()45const tabs = TabSelect({6width: 60,7tabWidth: 15,8options: [9 { name: "Tab 1", description: "First tab" },10 { name: "Tab 2", description: "Second tab" },11 { name: "Tab 3", description: "Third tab" },12],13})1415tabs.focus()16renderer.root.add(tabs)
##Keyboard navigation
When focused, the tab select responds to these keys:
← / [Move to previous tab
→ / ]Move to next tab
EnterSelect current tab
##Tabbed interface example
Swap panels when the selection changes:
1const container = Box({2width: 60,3height: 20,4borderStyle: "rounded",5})67const tabs = TabSelect({8width: 60,9tabWidth: 20,10options: [11 { name: "Home", description: "Dashboard" },12 { name: "Files", description: "Browse files" },13 { name: "Settings", description: "Preferences" },14],15})1617tabs.on("itemSelected", (index, option) => {18if (currentPanel) contentArea.remove(currentPanel)19currentPanel = panels[option.name]20contentArea.add(currentPanel)21})2223container.add(tabs)24container.add(contentArea)25tabs.focus()26renderer.root.add(container)
##Scroll behavior
When there are more tabs than fit in the width, the component automatically handles horizontal scrolling as you navigate with the keyboard. showScrollArrows renders indicators when tabs are clipped.
##Properties
properties
| prop | type | default | description |
|---|---|---|---|
| width | number | - | Total component width |
| options | TabSelectOption[] | [] | Available tabs |
| tabWidth | number | 20 | Width of each tab |
| backgroundColor | string | RGBA | transparent | Background color |
| textColor | string | RGBA | "#FFFFFF" | Normal tab text |
| focusedBackgroundColor | string | RGBA | "#1a1a1a" | Background when focused |
| selectedBackgroundColor | string | RGBA | "#334455" | Selected tab background |
| selectedTextColor | string | RGBA | "#FFFF00" | Selected tab text |
| selectedDescriptionColor | string | RGBA | "#CCCCCC" | Description text color |
| showScrollArrows | boolean | true | Show scroll indicators |
| showDescription | boolean | true | Show tab descriptions |
| showUnderline | boolean | true | Underline on selected tab |
| wrapSelection | boolean | false | Wrap around when navigating |
| keyBindings | TabSelectKeyBinding[] | - | Custom key bindings |
| keyAliasMap | Record<string, string> | - | Key alias mappings |