CxJS

Tabs

import { Tab } from 'cx/widgets'; Copied

Tabs are used to switch between different views or content sections. Each Tab component writes its tab value to the shared value binding when clicked.

<div className="flex flex-col items-start gap-4">
  <div>
    <Tab tab="tab1" value={m.tab} default>
      Tab 1
    </Tab>
    <Tab tab="tab2" value={m.tab}>
      Tab 2
    </Tab>
    <Tab tab="tab3" value={m.tab} disabled>
      Disabled
    </Tab>
  </div>
  <div>
    <Tab tab="tab1" value={m.tab} mod="line">
      Tab 1
    </Tab>
    <Tab tab="tab2" value={m.tab} mod="line">
      Tab 2
    </Tab>
    <Tab tab="tab3" value={m.tab} mod="line" disabled>
      Disabled
    </Tab>
  </div>
  <div>
    <div className="pl-2">
      <Tab tab="tab1" value={m.tab} mod="classic">
        Tab 1
      </Tab>
      <Tab tab="tab2" value={m.tab} mod="classic">
        Tab 2
      </Tab>
      <Tab tab="tab3" value={m.tab} mod="classic" disabled>
        Disabled
      </Tab>
    </div>
    <div className="border border-border bg-white p-4" text={m.tab} />
  </div>
</div>

Tab Content

Use the visible property with the equal helper to show content based on the selected tab:

<div>
  <div className="pl-2">
    <Tab tab="tab1" value={m.tab} mod="classic" default>
      Profile
    </Tab>
    <Tab tab="tab2" value={m.tab} mod="classic">
      Settings
    </Tab>
    <Tab tab="tab3" value={m.tab} mod="classic">
      Notifications
    </Tab>
  </div>
  <div className="border border-gray-300 bg-white p-4">
    <div visible={equal(m.tab, "tab1")}>Profile content goes here.</div>
    <div visible={equal(m.tab, "tab2")}>Settings content goes here.</div>
    <div visible={equal(m.tab, "tab3")}>Notifications content goes here.</div>
  </div>
</div>
Profile content goes here.

Configuration

PropertyTypeDescription
tabstring | numberValue to write to value when the tab is clicked.
valuestring | numberBinding to the currently selected tab. Tab appears active when value equals tab.
modstringVisual modifier. Common values: line, classic.
defaultbooleanSet to true to make this the default tab.
disabledbooleanSet to true to disable the tab.
focusOnMouseDownbooleanIf true, tab receives focus on mouse click. Default is false.
baseClassstringBase CSS class. Default is tab.
classNamestringAdditional CSS class to apply.
stylestring | objectAdditional styles to apply.