Grapes homepage1.57.0
  • Guide
  • Tokens
  • Components
    Grapes on GithubGrapes on Figma
    Interaction
    • Button
    • IconButton
    • FloatingActionBar
    • Link
    Icons
    • Icon
    • HighlightIcon
    Form
    • AmountInput
    • Autocomplete
    • AutocompleteMultiple
    • AutocompletePlace
    • CheckboxBox
    • CheckboxField
    • DatePicker
    • FormField
    • Input
    • OptionGroup
    • PasswordInput
    • PhoneInput
    • RadioBox
    • RadioField
    • RadioGroup
    • Select
    • SwitchField
    • TextArea
    • TextInput
    • Upload
    • UploadButton
    Feedback
    • Badge
    • Banner
    • Callout
    • EmptyState
    • Modal
    • ModalSlideshow
    • DeprecatedModalSlideshow
    • PageModal
    • Skeleton
    • Tag
    • Toast
    • Tooltip
    Data display
    • Accordion
    • Avatar
    • Box
    • Calendar
    • CalendarRange
    • CollapsibleList
    • FileCard
    • InfoTip
    • ListBox
    • ListView
    • Panel
    • SidePanel
    • DeprecatedPreview
    • Table
    • Timeline
    • useDateFormatter
    Navigation
    • DropdownItem
    • DropdownMenu
    • Navigation
    • NavigationItem
    • Popover
    • Tabs

    Tabs

    Tabs are used to organize content by grouping similar information on the same page.

    View source code
    • Usage
    • Props
    • Accessibility

    Import

    • Tabs: The wrapper around the tabs.
    • TabList: The list of tabs, can be above or below the TabPanels.
    • Tab: The tab name, supports a ReactNode
    • TabPanels: The list of tab panels
    • TabPanel: The content in one tab

    Basic usage

    <Tabs>
      <TabList className="mb-16">
        <Tab>Information</Tab>
        <Tab>Roles</Tab>
        <Tab>Settings & Policies</Tab>
      </TabList>
      <TabPanels>
        <TabPanel>First panel</TabPanel>
        <TabPanel>Second panel</TabPanel>
        <TabPanel>Third panel</TabPanel>
      </TabPanels>
    </Tabs>
    

    Fitted

    Use the isFitted prop on the TabList component to make the tabs fit their container.

    <Tabs>
      <TabList isFitted className="mb-16">
        <Tab>Information</Tab>
        <Tab>Roles</Tab>
        <Tab>Settings & Policies</Tab>
      </TabList>
      <TabPanels>
        <TabPanel>First panel</TabPanel>
        <TabPanel>Second panel</TabPanel>
        <TabPanel>Third panel</TabPanel>
      </TabPanels>
    </Tabs>
    

    Default tab index

    Use the defaultTabIndex prop to make a tab initially active.

    <Tabs defaultTabIndex={2}>...</Tabs>
    

    Customized

    The Tab accepts any kind of content, it can be customized as needed.

    <Tabs>
      <TabList className="mb-16">
        <Tab>Information</Tab>
        <Tab>
          Roles
          <Badge className="ml-8" variant="primary">
            3
          </Badge>
        </Tab>
        <Tab>
          <Icon
            className="mr-8"
            color="var(--grapes-color-content-warning-default)"
            name="warning"
          />
          Settings & Policies
        </Tab>
      </TabList>
    </Tabs>
    

    Controlled

    A tab's state can be controlled. Make sure to include the tabIndex and onChange props.

    const Demo = () => {
      const [value, setValue] = useState(2);
    
      return (
        <>
          <input
            className="appearance-auto"
            type="range"
            min="0"
            max="2"
            step="1"
            value={value}
            onChange={(e) => setValue(Number(e.target.value))}
          />
          <Tabs tabIndex={value} onChange={setValue}>
            <TabList>
              <Tab>Tab One</Tab>
              <Tab>Tab Two</Tab>
              <Tab>Tab Three</Tab>
            </TabList>
            <TabPanels>
              <TabPanel>First panel</TabPanel>
              <TabPanel>Second panel</TabPanel>
              <TabPanel>Third panel</TabPanel>
            </TabPanels>
          </Tabs>
        </>
      );
    };
    
    First panel
    Second panel
    Third panel
    First panel
    Second panel
    Third panel
    First panel
    Second panel
    Third panel
    First panel
    Second panel
    Third panel
    First panel
    Second panel
    Third panel