Tabs

Import
import { Tabs } from "reshaped";
import type { TabsProps } from "reshaped";
Storybook
Full keyboard navigation
Can be controlled and uncontrolled
Can be used as a form control
Works with any content


Usage

Tabs compound component consists of multiple subcomponents: List, Item and Panel that should be used together. Each Item and Panel should have unique matching IDs within the Tabs parent. As you can see, every Item has an icon and children support.

Variants

Tabs support pills, pills-elevated and borderless variants.

borderless variant is helpful when used with the parent component that already provides its border. For example, you can use it together with the Divider component and custom padding value.

pills and pills-elevated variants can be used for the less prominent secondary navigation.

Controlled/uncontrolled

If you provide defaultValue to the component, it will select a tab on the component mount and keep the default selection logic later.

If you provide value, a controlled mode will be turned on, and you will have to change the component's state manually. This will still call the onChange handler, letting you customize the selection logic. For instance, you can fetch data for the tab before making it active.

Equal width items

You can stretch the tab items to keep their width equal with itemWidth property.

Panel composition

Panels don't have to be located at the top level of the component. You can place them anywhere inside the Tabs scope, and they will still work as expected.

This approach lets you easily customize their styles and animate their appearance using 3rd-party libraries.

Using in forms

Tabs can be used in forms as radio buttons if you pass the name property to them. That will automatically adjust their markup to native input elements, and the selected value will support form submission.

Accessibility

Tabs component provides all required aria- attributes and roles to its elements. To provide a description to the tablist element, you can use attributes={{ 'aria-label': 'Tabs label' }}.

Keyboard navigation:

When used as regular tabs:

  • Pressing Tab will place the focus on the active tab item when the focus moves into the tab list
  • Left and right arrow keys move focus across tab items
  • Space and Enter select the focused tab
  • Home moves focus to the first tab item
  • End moves focus to the last tab item

When used in forms:

  • Left and right arrow keys change the selected tab
Previous