Tabs

import {Tab, Tabs} from "@qualcomm-ui/react/tabs"

Examples

Horizontal

The default orientation is horizontal. The left and right arrow keys can be used to navigate between tabs.

Documents

Vertical

In vertical orientation, the up and down arrow keys are used instead.

Documents

Icons and variants

Tabs support start and end icons. Customize the variant with the iconVariant prop. Use the variant prop to change the appearance of the tab.

<Tabs.Root>
  <TabContent />
</Tabs.Root>
<Tabs.Root iconVariant="filled">
  <TabContent />
</Tabs.Root>
<Tabs.Root variant="contained">
  <TabContent />
</Tabs.Root>
<Tabs.Root iconVariant="filled" variant="contained">
  <TabContent />
</Tabs.Root>

Controlled Value

The tab's active value can be controlled via the value, onValueChange, and defaultValue properties. These props follow our controlled state pattern.

Software Panel

Sizes

Line

The line variant supports four sizes: sm, md, lg, and xl

sm
md
lg
xl

Contained

The contained variant supports only two sizes: sm and md

Lazy Mounted

Use the lazyMount and unmountOnExit props to control render behavior for inactive tabs.

This component has been alive for 0 seconds

Disabled

Disable specific tabs with the disabled prop on the <Tab.Root> component.

<Tab.Root disabled value="products">
  <Tab.Button endIcon={Smartphone}>Products</Tab.Button>
</Tab.Root>

URL Search Parameters

The following example demonstrates how to render tabs that sync with the URL search parameters using react-router.

Documents

Context

Use the <Tabs.Context> component to access the tabs API from JSX.

<Tabs.Context>
  {(context) => (
    <>
      <Tabs.Panel value="tab-1">
        <Button
          endIcon={ChevronRight}
          onClick={() => context.setValue("tab-2")}
          size="sm"
          variant="outline"
        >
          Go to next tab
        </Button>
      </Tabs.Panel>
      <Tabs.Panel className="flex items-center gap-2" value="tab-2">
        <Button
          onClick={() => context.setValue("tab-1")}
          size="sm"
          startIcon={ChevronLeft}
          variant="outline"
        >
          Go to prev tab
        </Button>
        <Button
          endIcon={ChevronRight}
          onClick={() => context.setValue("tab-3")}
          size="sm"
          variant="outline"
        >
          Go to next tab
        </Button>
      </Tabs.Panel>
      <Tabs.Panel value="tab-3">
        <Button
          onClick={() => context.setValue("tab-2")}
          size="sm"
          startIcon={ChevronLeft}
          variant="outline"
        >
          Go to previous tab
        </Button>
      </Tabs.Panel>
    </>
  )}
</Tabs.Context>

Add and Remove Tabs

Tab Content 1

Lorem ipsum dolor sit amet consectetur adipiscing elit. Quisque faucibus ex sapien vitae pellentesque sem placerat. In id cursus mi pretium tellus duis convallis. Tempus leo eu aenean sed diam urna tempor. Pulvinar vivamus fringilla lacus nec metus bibendum egestas.

API

Tabs

<Tabs.Root>

Groups all parts of the tabs. Renders a <div> element by default.
PropTypeDefault
The activation mode of the tabs.
  • 'automatic': Tabs are activated when receiving focus
  • 'manual': Tabs are activated when clicked or the enter key is pressed.
| 'automatic'
| 'manual'
"automatic"
If true, the indicator's position change will animate when the active tab changes. Only applies to the line variant.
boolean
true
React children prop.
Determines whether tabs act as a standalone composite widget (true) or as a non-focusable component within another widget (false).
boolean
true
The initial selected tab value when rendered. Use when you don't need to control the selected tab value.
string
Whether the active tab can be deselected when clicking on it.
boolean
The document's text/writing direction.
'ltr' | 'rtl'
'ltr'
A root node to correctly resolve document in custom environments. i.e., Iframes, Electron.
    () =>
    | Node
    | ShadowRoot
    | Document
    The visual style of tab icons.
    • 'ghost': The icon is rendered with a transparent background.
    • 'filled': The icon is rendered with a solid background.
    | 'ghost'
    | 'filled'
    'ghost'
    
    When true, the component will not be rendered in the DOM until it becomes visible or active.
    boolean
    false
    
    Whether the keyboard navigation will loop from last tab to first, and vice versa.
    boolean
    true
    
    Callback to be called when the focused tab changes
      (
      value: string,
      ) => void
      Callback to be called when the selected/active tab changes
        (
        value: string,
        ) => void
        The orientation of the tabs. Can be horizontal or vertical
        • 'horizontal': only left and right arrow key navigation will work.
        • 'vertical': only up and down arrow key navigation will work.
        | 'horizontal'
        | 'vertical'
        "horizontal"
        
        Allows you to replace the component's HTML element with a different tag or component. Learn more
        | ReactElement
        | ((
        props: object,
        ) => ReactElement)
        Governs the size of the tab text, icons, spacing, and padding. Note that lg and xl are not supported by the contained variant.
        | 'sm'
        | 'md'
        | 'lg'
        | 'xl'
        'md'
        
        Specifies the localized strings that identifies the accessibility elements and their states
        {
        listLabel?: string
        }
        When true, the component will be completely removed from the DOM when it becomes inactive or hidden, rather than just being hidden with CSS.
        boolean
        false
        
        The controlled selected tab value
        string
        Governs the appearance of the tab.
        • 'line': active tab items have a line underneath them.
        • 'contained': active tab items have a box-like appearance.
        | 'line'
        | 'contained'
        Type
        | 'automatic'
        | 'manual'
        Description
        The activation mode of the tabs.
        • 'automatic': Tabs are activated when receiving focus
        • 'manual': Tabs are activated when clicked or the enter key is pressed.
        Type
        boolean
        Description
        If true, the indicator's position change will animate when the active tab changes. Only applies to the line variant.
        Description
        React children prop.
        Type
        boolean
        Description
        Determines whether tabs act as a standalone composite widget (true) or as a non-focusable component within another widget (false).
        Type
        string
        Description
        The initial selected tab value when rendered. Use when you don't need to control the selected tab value.
        Type
        boolean
        Description
        Whether the active tab can be deselected when clicking on it.
        Type
        'ltr' | 'rtl'
        Description
        The document's text/writing direction.
        Type
        () =>
        | Node
        | ShadowRoot
        | Document
        Description
        A root node to correctly resolve document in custom environments. i.e., Iframes, Electron.
          Type
          | 'ghost'
          | 'filled'
          Description
          The visual style of tab icons.
          • 'ghost': The icon is rendered with a transparent background.
          • 'filled': The icon is rendered with a solid background.
          Type
          boolean
          Description
          When true, the component will not be rendered in the DOM until it becomes visible or active.
          Type
          boolean
          Description
          Whether the keyboard navigation will loop from last tab to first, and vice versa.
          Type
          (
          value: string,
          ) => void
          Description
          Callback to be called when the focused tab changes
            Type
            (
            value: string,
            ) => void
            Description
            Callback to be called when the selected/active tab changes
              Type
              | 'horizontal'
              | 'vertical'
              Description
              The orientation of the tabs. Can be horizontal or vertical
              • 'horizontal': only left and right arrow key navigation will work.
              • 'vertical': only up and down arrow key navigation will work.
              Type
              | ReactElement
              | ((
              props: object,
              ) => ReactElement)
              Description
              Allows you to replace the component's HTML element with a different tag or component. Learn more
              Type
              | 'sm'
              | 'md'
              | 'lg'
              | 'xl'
              Description
              Governs the size of the tab text, icons, spacing, and padding. Note that lg and xl are not supported by the contained variant.
              Type
              {
              listLabel?: string
              }
              Description
              Specifies the localized strings that identifies the accessibility elements and their states
              Type
              boolean
              Description
              When true, the component will be completely removed from the DOM when it becomes inactive or hidden, rather than just being hidden with CSS.
              Type
              string
              Description
              The controlled selected tab value
              Type
              | 'line'
              | 'contained'
              Description
              Governs the appearance of the tab.
              • 'line': active tab items have a line underneath them.
              • 'contained': active tab items have a box-like appearance.

              <Tabs.List>

              Container for the tab buttons. Renders a <div> element by default.
              PropType
              React children prop.
              id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
              string
              Allows you to replace the component's HTML element with a different tag or component. Learn more
              | ReactElement
              | ((
              props: object,
              ) => ReactElement)
              Description
              React children prop.
              Type
              string
              Description
              id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
              Type
              | ReactElement
              | ((
              props: object,
              ) => ReactElement)
              Description
              Allows you to replace the component's HTML element with a different tag or component. Learn more

              <Tabs.Indicator>

              Visual indicator that highlights the active tab. Renders a <div> element by default. You only need to render a single <Tabs.Indicator> component per tab list.
              <Tabs.Root>
              <Tabs.List>
              <Tabs.Indicator />
              <Tab.Root value="tab-1">
              <Tab.Button>Tab 1</Tab.Button>
              </Tab.Root>
              </Tabs.List>
              </Tabs.Root>
              PropType
              id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
              string
              Allows you to replace the component's HTML element with a different tag or component. Learn more
              | ReactElement
              | ((
              props: object,
              ) => ReactElement)
              Type
              string
              Description
              id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
              Type
              | ReactElement
              | ((
              props: object,
              ) => ReactElement)
              Description
              Allows you to replace the component's HTML element with a different tag or component. Learn more

              <Tabs.Panel>

              Content area associated with a tab. Renders a <div> element by default.
              PropType
              The value of the associated tab
              string
              React children prop.
              id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
              string
              Allows you to replace the component's HTML element with a different tag or component. Learn more
              | ReactElement
              | ((
              props: object,
              ) => ReactElement)
              Type
              string
              Description
              The value of the associated tab
              Description
              React children prop.
              Type
              string
              Description
              id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
              Type
              | ReactElement
              | ((
              props: object,
              ) => ReactElement)
              Description
              Allows you to replace the component's HTML element with a different tag or component. Learn more

              Tab

              <Tab.Root>

              Groups all parts of a single tab. Renders a <div> element by default.
              PropType
              The value of the tab
              string
              React children prop.
              Whether the tab is disabled
              boolean
              Allows you to replace the component's HTML element with a different tag or component. Learn more
              | ReactElement
              | ((
              props: object,
              ) => ReactElement)
              Type
              string
              Description
              The value of the tab
              Description
              React children prop.
              Type
              boolean
              Description
              Whether the tab is disabled
              Type
              | ReactElement
              | ((
              props: object,
              ) => ReactElement)
              Description
              Allows you to replace the component's HTML element with a different tag or component. Learn more

              <Tab.Button>

              Button that activates its associated tab panel. Renders a <button> element by default.
              PropType
              React children prop.
              Use the disabled prop on the parent <Tab.Root> component instead.
              never
              Icon positioned after the text content. If supplied as a LucideIcon, the size will automatically match the size prop. Supply as a ReactElement for additional customization.
              | LucideIcon
              | ReactNode
              id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
              string
              Allows you to replace the component's HTML element with a different tag or component. Learn more
              | ReactElement
              | ((
              props: object,
              ) => ReactElement)
              Icon positioned before the text content. If supplied as a LucideIcon, the size will automatically match the size. Supply as a ReactElement for additional customization.
              | LucideIcon
              | ReactNode
              Description
              React children prop.
              Type
              never
              Description
              Use the disabled prop on the parent <Tab.Root> component instead.
              Type
              | LucideIcon
              | ReactNode
              Description
              Icon positioned after the text content. If supplied as a LucideIcon, the size will automatically match the size prop. Supply as a ReactElement for additional customization.
              Type
              string
              Description
              id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
              Type
              | ReactElement
              | ((
              props: object,
              ) => ReactElement)
              Description
              Allows you to replace the component's HTML element with a different tag or component. Learn more
              Type
              | LucideIcon
              | ReactNode
              Description
              Icon positioned before the text content. If supplied as a LucideIcon, the size will automatically match the size. Supply as a ReactElement for additional customization.

              <Tab.DismissButton>

              Button that dismisses a tab. Renders a <button> element by default.
              PropType
              React children prop.
              Allows you to replace the component's HTML element with a different tag or component. Learn more
              | ReactElement
              | ((
              props: object,
              ) => ReactElement)
              Description
              React children prop.
              Type
              | ReactElement
              | ((
              props: object,
              ) => ReactElement)
              Description
              Allows you to replace the component's HTML element with a different tag or component. Learn more

              <Tabs.Context>

              PropType
              Render Prop that provides the current TabsApi context.
              Description
              Render Prop that provides the current TabsApi context.

              TabsApi

              PropType
              Clears the value of the tabs.
                () => void
                Set focus on the selected tab button
                  () => void
                  The value of the tab that is currently focused.
                  string
                  Returns the state of the tab with the given props
                    (props: {
                    disabled?: boolean
                    value: string
                    }) => {
                    disabled: boolean
                    focused: boolean
                    selected: boolean
                    }
                    Sets the indicator rect to the tab with the given value
                      (
                      value: string,
                      ) => void
                      Sets the value of the tabs.
                        (
                        value: string,
                        ) => void
                        Synchronizes the tab index of the content element. Useful when rendering tabs within a select or combobox
                          () => void
                          The current value of the tabs.
                          string
                          Type
                          () => void
                          Description
                          Clears the value of the tabs.
                            Type
                            () => void
                            Description
                            Set focus on the selected tab button
                              Type
                              string
                              Description
                              The value of the tab that is currently focused.
                              Type
                              (props: {
                              disabled?: boolean
                              value: string
                              }) => {
                              disabled: boolean
                              focused: boolean
                              selected: boolean
                              }
                              Description
                              Returns the state of the tab with the given props
                                Type
                                (
                                value: string,
                                ) => void
                                Description
                                Sets the indicator rect to the tab with the given value
                                  Type
                                  (
                                  value: string,
                                  ) => void
                                  Description
                                  Sets the value of the tabs.
                                    Type
                                    () => void
                                    Description
                                    Synchronizes the tab index of the content element. Useful when rendering tabs within a select or combobox
                                      Type
                                      string
                                      Description
                                      The current value of the tabs.