Skip to main content

Common Examples

import { Tab } from "@servicetitan/anvil2";

function ExampleComponent() {
  return (
    <Tab>
      <Tab.List>
        <Tab.Button id="t-1" controls="p-1">
          Tab 1
        </Tab.Button>
        <Tab.Button id="t-2" controls="p-2">
          Tab 2
        </Tab.Button>
      </Tab.List>
      <Tab.Panel id="p-1">Tab 1 content...</Tab.Panel>
      <Tab.Panel id="p-2">Tab 2 content...</Tab.Panel>
    </Tab>
  );
}

Basic Tabs

Tabs are used to separate large blocks of content relevant to the user’s current context. Four components are used to makeup Anvil tabs: Tab, Tab.List, Tab.Button, and Tab.Panel.

Notes

  • There should always be an equal number of Tab.Button and Tab.Panel components.
  • Values in the controls prop of each Tab.Button component should match the id of the corresponding Tab.Panel.

Changing the Default Tab

By default, the content of the Tab.Panel associated to the first Tab.Button will be displayed. To change this behavior, supply the index of the Tab.Button that should be displayed first to the defaultIndex of the parent Tab.

React Accessibility

  • An Anvil Tab.Button cannot be disabled.
  • When a Tab.Button has focus, the left and right arrow keys and enter can be used to navigate tabs.
For more guidance on custom tab behaviors and keyboard interaction, see changing content best practices.
Last modified on January 23, 2026