Saved media
Tabs organize groups of related content that are at the same level of hierarchy, and let people switch between them. Use tabs to group related content, not sequential content.
To move between the main destinations of an app, use a navigation bar or a navigation rail instead.
Tabs are composed of four parts, as with React Aria's Tabs:
| Part | Use |
|---|---|
Tabs | The container of the row and the panels. It holds the selection. |
TabList | The row of tabs |
Tab | A tab. Selecting it shows its panel. |
TabPanel | What a tab shows |
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'Basic tabs
Put a TabList of Tabs and a TabPanel for each tab in Tabs. Give a tab and its panel the same id.
import { Icon, Tab, TabList, TabPanel, Tabs } from '@material-web/react'
export default function Basic() {
return (
<Tabs className="w-full">
<TabList>
<Tab id="flights">
<Icon name="flight" />
Flights
</Tab>
<Tab id="trips">
<Icon name="luggage" />
Trips
</Tab>
<Tab id="explore">
<Icon name="explore" />
Explore
</Tab>
</TabList>
<TabPanel id="flights" className="p-space-300 text-body-md">
Flights are listed here.
</TabPanel>
<TabPanel id="trips" className="p-space-300 text-body-md">
Trips are listed here.
</TabPanel>
<TabPanel id="explore" className="p-space-300 text-body-md">
Places to explore are listed here.
</TabPanel>
</Tabs>
)
}To render the tabs from data, pass items to the TabList and a function as its children. See Collections.
Tabs come in two variants. Set variant on the Tabs to primary (the default) or secondary.
Primary tabs
Primary tabs show the main content destinations, at the top of the content pane under an app bar. Use them when one set of tabs is needed. A selected primary tab is shown in the primary color, over an indicator as wide as its content.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'
export default function Primary() {
return (
<Tabs>
<TabList>
<Tab id="flights">Flights</Tab>
<Tab id="trips">Trips</Tab>
<Tab id="explore">Explore</Tab>
</TabList>
<TabPanel id="flights" className="p-space-300 text-body-md">
Flights are listed here.
</TabPanel>
<TabPanel id="trips" className="p-space-300 text-body-md">
Trips are listed here.
</TabPanel>
<TabPanel id="explore" className="p-space-300 text-body-md">
Places to explore are listed here.
</TabPanel>
</Tabs>
)
}Secondary tabs
Secondary tabs separate related content within a content area, and establish hierarchy. A selected secondary tab is shown over an indicator across the whole tab.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'
export default function Secondary() {
return (
<Tabs variant="secondary">
<TabList>
<Tab id="overview">Overview</Tab>
<Tab id="specifications">Specifications</Tab>
</TabList>
<TabPanel id="overview" className="p-space-300 text-body-md">
An overview of the product.
</TabPanel>
<TabPanel id="specifications" className="p-space-300 text-body-md">
Every specification of the product.
</TabPanel>
</Tabs>
)
}Use secondary tabs when a screen needs more than one level of tabs, and place them below the primary tabs, such as in the panel of a primary tab.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'
const destinations = ['Flights', 'Trips', 'Explore']
export default function TwoLevels() {
return (
<Tabs>
<TabList>
{destinations.map((name) => (
<Tab key={name} id={name}>
{name}
</Tab>
))}
</TabList>
{destinations.map((name) => (
<TabPanel key={name} id={name}>
<Tabs variant="secondary">
<TabList>
<Tab id="upcoming">Upcoming</Tab>
<Tab id="past">Past</Tab>
</TabList>
<TabPanel id="upcoming" className="p-space-300 text-body-md">
Upcoming {name.toLowerCase()}.
</TabPanel>
<TabPanel id="past" className="p-space-300 text-body-md">
Past {name.toLowerCase()}.
</TabPanel>
</Tabs>
</TabPanel>
))}
</Tabs>
)
}Icons
Write a tab's icon and label as its children. An Icon is sized and colored by the tab. Use icons on every tab of a row, or on none of them.
For a tab with an icon alone, set an aria-label.
import { Icon, Tab, TabList, TabPanel, Tabs } from '@material-web/react'
export default function Icons() {
return (
<Tabs>
<TabList>
<Tab id="favorites" aria-label="Favorites">
<Icon name="favorite" />
</Tab>
<Tab id="nearby" aria-label="Nearby">
<Icon name="location_on" />
</Tab>
<Tab id="recent" aria-label="Recent">
<Icon name="history" />
</Tab>
</TabList>
<TabPanel id="favorites" className="p-space-300 text-body-md">
Your favorites.
</TabPanel>
<TabPanel id="nearby" className="p-space-300 text-body-md">
What is nearby.
</TabPanel>
<TabPanel id="recent" className="p-space-300 text-body-md">
What you opened recently.
</TabPanel>
</Tabs>
)
}Selection
Set the initial selection with defaultSelectedKey, or control it with selectedKey and onSelectionChange, as with React Aria's selection. The key is the id of the selected tab. With neither, the first tab is selected.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'
import { useState } from 'react'
import type { Key } from 'react-aria-components'
const destinations = ['Flights', 'Trips', 'Explore']
export default function Controlled() {
const [selected, setSelected] = useState<Key>('Trips')
return (
<Tabs selectedKey={selected} onSelectionChange={setSelected}>
<TabList>
{destinations.map((name) => (
<Tab key={name} id={name}>
{name}
</Tab>
))}
</TabList>
{destinations.map((name) => (
<TabPanel key={name} id={name} className="p-space-300 text-body-md">
Selected: {String(selected)}
</TabPanel>
))}
</Tabs>
)
}A mouse selects a tab when it is pressed, and a touch when it is released.
Keyboard activation
Set keyboardActivation to manual (the default) or automatic. With manual, the arrow keys move the focus between the tabs, and Space or Enter selects the focused one. With automatic, the arrow keys select the tab they move to.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'
export default function AutomaticActivation() {
return (
<Tabs keyboardActivation="automatic">
<TabList>
<Tab id="flights">Flights</Tab>
<Tab id="trips">Trips</Tab>
<Tab id="explore">Explore</Tab>
</TabList>
<TabPanel id="flights" className="p-space-300 text-body-md">
Flights are listed here.
</TabPanel>
<TabPanel id="trips" className="p-space-300 text-body-md">
Trips are listed here.
</TabPanel>
<TabPanel id="explore" className="p-space-300 text-body-md">
Places to explore are listed here.
</TabPanel>
</Tabs>
)
}Keeping panels mounted
A TabPanel is rendered only while its tab is selected, so what a person entered in it is lost when they switch tabs. Set shouldForceMount on a panel to keep it rendered. A panel whose tab is not selected is then inert, and it is still shown: hide it with a class such as inert:hidden.
import { Tab, TabList, TabPanel, Tabs, TextField } from '@material-web/react'
export default function KeepMounted() {
return (
<Tabs>
<TabList>
<Tab id="outbound">Outbound</Tab>
<Tab id="return">Return</Tab>
</TabList>
<TabPanel id="outbound" shouldForceMount className="p-space-300 inert:hidden">
<TextField label="Notes for the outbound flight" className="w-full" />
</TabPanel>
<TabPanel id="return" shouldForceMount className="p-space-300 inert:hidden">
<TextField label="Notes for the return flight" className="w-full" />
</TabPanel>
</Tabs>
)
}Disabled
Set isDisabled on a Tab to disable it, or list its id in the disabledKeys of the Tabs. A disabled tab cannot be selected or focused, and the arrow keys skip it. Set isDisabled on the Tabs to disable every tab.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'
export default function Disabled() {
return (
<Tabs disabledKeys={['explore']}>
<TabList>
<Tab id="flights">Flights</Tab>
<Tab id="trips" isDisabled>
Trips
</Tab>
<Tab id="explore">Explore</Tab>
<Tab id="saved">Saved</Tab>
</TabList>
<TabPanel id="flights" className="p-space-300 text-body-md">
Flights are listed here.
</TabPanel>
<TabPanel id="trips" className="p-space-300 text-body-md">
Trips are listed here.
</TabPanel>
<TabPanel id="explore" className="p-space-300 text-body-md">
Places to explore are listed here.
</TabPanel>
<TabPanel id="saved" className="p-space-300 text-body-md">
Saved places are listed here.
</TabPanel>
</Tabs>
)
}Icon position
The variant places the icon of a tab that has a label too:
| Variant | Icon | Row height |
|---|---|---|
primary | Over the label | 64dp |
secondary | Before the label | 48dp |
A row of tabs with a label alone, or an icon alone, is 48dp tall.
import { Icon, Tab, TabList, TabPanel, Tabs } from '@material-web/react'
export default function IconPosition() {
return (
<div className="flex flex-col gap-space-300">
<Tabs>
<TabList>
<Tab id="overview">
<Icon name="summarize" />
Overview
</Tab>
<Tab id="specifications">
<Icon name="list_alt" />
Specifications
</Tab>
</TabList>
<TabPanel id="overview" className="p-space-300 text-body-md">
A primary tab stacks its icon over its label.
</TabPanel>
<TabPanel id="specifications" className="p-space-300 text-body-md">
Every specification of the product.
</TabPanel>
</Tabs>
<Tabs variant="secondary">
<TabList>
<Tab id="overview">
<Icon name="summarize" />
Overview
</Tab>
<Tab id="specifications">
<Icon name="list_alt" />
Specifications
</Tab>
</TabList>
<TabPanel id="overview" className="p-space-300 text-body-md">
A secondary tab puts its icon before its label.
</TabPanel>
<TabPanel id="specifications" className="p-space-300 text-body-md">
Every specification of the product.
</TabPanel>
</Tabs>
</div>
)
}Fixed tabs
By default, the tabs are fixed: they show all at once and divide the row equally, whatever the length of their labels. Fixed tabs are best for switching between related content quickly, such as between transportation methods in a map.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'
export default function Fixed() {
return (
<Tabs>
<TabList>
<Tab id="driving">Driving</Tab>
<Tab id="transit">Public transit</Tab>
<Tab id="walking">Walking</Tab>
</TabList>
<TabPanel id="driving" className="p-space-300 text-body-md">
Routes by car.
</TabPanel>
<TabPanel id="transit" className="p-space-300 text-body-md">
Routes by bus and train.
</TabPanel>
<TabPanel id="walking" className="p-space-300 text-body-md">
Routes on foot.
</TabPanel>
</Tabs>
)
}The row is as wide as the Tabs. To make it narrower than its container, set a width on the Tabs in className.
Scrollable tabs
When a set of tabs cannot fit on screen, set isScrollable on the TabList. Each tab is then as wide as its label, and the row scrolls sideways. Scrollable tabs can have longer labels and a larger number of tabs, and are best for browsing on touch screens.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'
const breeds = [
'Akita',
'Alaskan',
'Australian Shepherd',
'Azawakh',
'Barbet',
'Basenji',
'Beagle',
'Border Collie',
'Boxer',
'Bulldog',
'Chihuahua',
'Dalmatian',
]
export default function Scrollable() {
return (
<Tabs defaultSelectedKey="Alaskan">
<TabList isScrollable>
{breeds.map((breed) => (
<Tab key={breed} id={breed}>
{breed}
</Tab>
))}
</TabList>
{breeds.map((breed) => (
<TabPanel key={breed} id={breed} className="p-space-300 text-body-md">
About the {breed}.
</TabPanel>
))}
</Tabs>
)
}A scrollable row scrolls to the selected tab, and to a tab that the keyboard focuses. Its first and last tab are 52dp from the ends of the row.
Long labels
A label wraps when its tab is too narrow for it, and the row grows with it. To limit a label to two lines, put it in an element of your own with line-clamp-2.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'
export default function LongLabels() {
return (
<>
<Tabs className="w-80">
<TabList>
<Tab id="flights">Flights</Tab>
<Tab id="trips">Trips and itineraries you have planned</Tab>
<Tab id="explore">Explore</Tab>
</TabList>
<TabPanel id="flights" className="p-space-300 text-body-md">
Flights are listed here.
</TabPanel>
<TabPanel id="trips" className="p-space-300 text-body-md">
Trips are listed here.
</TabPanel>
<TabPanel id="explore" className="p-space-300 text-body-md">
Places to explore are listed here.
</TabPanel>
</Tabs>
<Tabs className="w-80">
<TabList>
<Tab id="flights">Flights</Tab>
<Tab id="trips">
<span className="line-clamp-2">Trips and itineraries you have planned</span>
</Tab>
<Tab id="explore">Explore</Tab>
</TabList>
<TabPanel id="flights" className="p-space-300 text-body-md">
Flights are listed here.
</TabPanel>
<TabPanel id="trips" className="p-space-300 text-body-md">
Trips are listed here.
</TabPanel>
<TabPanel id="explore" className="p-space-300 text-body-md">
Places to explore are listed here.
</TabPanel>
</Tabs>
</>
)
}Orientation
Set orientation="vertical" on the Tabs to stack the tabs in a column beside their panels. Each tab is as tall as its content, and the column is as wide as its widest tab, with the divider and the active indicator at its inline end. The up and down arrow keys then move between the tabs.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'
export default function Vertical() {
return (
<Tabs orientation="vertical" className="w-full">
<TabList>
<Tab id="account">Account</Tab>
<Tab id="notifications">Notifications</Tab>
<Tab id="privacy">Privacy</Tab>
</TabList>
<TabPanel id="account" className="p-space-300 text-body-md">
Account settings are listed here.
</TabPanel>
<TabPanel id="notifications" className="p-space-300 text-body-md">
Notification settings are listed here.
</TabPanel>
<TabPanel id="privacy" className="p-space-300 text-body-md">
Privacy settings are listed here.
</TabPanel>
</Tabs>
)
}With isScrollable on the TabList, the column scrolls up and down when it is taller than the Tabs. Set a height on the Tabs in className to limit it.
Links
Give a tab an href to make it a link, for tabs that move between the pages of an app. Pressing a link tab follows its link and does not change the selection, so set selectedKey from the current location.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'
import { useState } from 'react'
import { RouterProvider } from 'react-aria-components'
export default function NavTabs() {
// Stands in for the app's router: it keeps the current location in state.
const [location, setLocation] = useState('#flights')
return (
<RouterProvider navigate={setLocation}>
<Tabs selectedKey={location}>
<TabList>
<Tab id="#flights" href="#flights">
Flights
</Tab>
<Tab id="#trips" href="#trips">
Trips
</Tab>
<Tab id="#explore" href="#explore">
Explore
</Tab>
</TabList>
<TabPanel id={location} className="p-space-300 text-body-md">
The location is {location}.
</TabPanel>
</Tabs>
</RouterProvider>
)
}Third-party routing library
A tab's link goes through React Aria's RouterProvider. Wrap the app in it once to follow the links with a client-side router, in place of a full page load. See Routing.
With React Router, read the selected tab from the location:
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'
import { Outlet, useLocation } from 'react-router'
function SectionTabs() {
const { pathname } = useLocation()
return (
<Tabs selectedKey={pathname}>
<TabList>
<Tab id="/flights" href="/flights">
Flights
</Tab>
<Tab id="/trips" href="/trips">
Trips
</Tab>
</TabList>
<TabPanel id={pathname}>
<Outlet />
</TabPanel>
</Tabs>
)
}Customization
Each part takes its own className: Tabs, TabList, Tab and TabPanel. A class of yours replaces the part's own class for the same property. See Styling for the classes, the states and the theme.
Pass a function as a tab's children to render them from its state: isHovered, isPressed, isFocused, isFocusVisible, isSelected and isDisabled. In this example, the icon of the selected tab is filled.
import { Icon, Tab, TabList, TabPanel, Tabs } from '@material-web/react'
const destinations = [
['Flights', 'flight', 'Flights are listed here.'],
['Trips', 'luggage', 'Trips are listed here.'],
['Explore', 'explore', 'Places to explore are listed here.'],
] as const
export default function FunctionChildren() {
return (
<Tabs>
<TabList>
{destinations.map(([name, icon]) => (
<Tab key={name} id={name}>
{({ isSelected }) => (
<>
<Icon name={icon} className={isSelected ? 'icon-filled' : undefined} />
{name}
</>
)}
</Tab>
))}
</TabList>
{destinations.map(([name, , text]) => (
<TabPanel key={name} id={name} className="p-space-300 text-body-md">
{text}
</TabPanel>
))}
</Tabs>
)
}- Color: The label of a selected primary tab and the active indicator of both variants use the
primarycolor role. To change them together, set that role on theTabs. See Theme. - Density: Add
density-1,density-2ordensity-3to theTabs, or to an element around it. Each step makes the row 4dp shorter. See Density. - States: Style a tab's state with its variant, such as
hover:,selected:ordisabled:. See States. - Functions: The children of a
TabPanelcan be a function ofisFocused,isFocusVisibleandisInert, and the children ofTabsa function of itsorientation. TheclassNameandstyleof aTabListcan be functions of its state. See Children as a function. - Every tab: To restyle all the tabs at once, change the theme.
Limitations
Scroll buttons
A scrollable row has no scroll buttons and shows no scrollbar. People scroll it with a swipe, a trackpad or the keyboard.
Use cases
Material lists what people should be able to do with assistive technology:
- Undertake actions or invoke navigation to a new destination with assistive tech
- Select an action or destination from an off screen tab with assistive tech
- Maintain access of primary actions when the content is in a scrolled state
Interaction and style
- States: Hovering a tab shows a state layer over it, and a press shows a ripple. An inactive tab's label darkens while it is hovered or focused. Keyboard focus shows a focus ring inside the tab, and a click does not.
- Touch target: Every tab has a touch target of at least 48dp, at every density.
- Color contrast: With the default colors, the labels keep 4.5:1 contrast and the active indicator 3:1 with the surface, in the light and dark schemes at every contrast level. Keep that contrast when you change the
primaryrole, as in Customization. - Text size: A label wraps when its tab is too narrow for it, and the row grows with it. See Long labels.
- Density: Each density step makes the row 4dp shorter, and each tab keeps its 48dp touch target. Material advises against denser tabs by default: apply a density only when people choose one, such as a denser layout, and keep the controls that change it at least 48 by 48dp.
- Motion: With reduced motion, the active indicator moves at once, and a scrollable row scrolls at once.
- Forced colors: In forced colors, the active indicator, the divider and the focus ring stay visible, and a disabled tab is drawn in the system's gray text color.
- Right to left: In a right-to-left direction, the row starts at the right, and a vertical row's divider is on its left.
- Horizontal scrolling: Set
isScrollablewhen the tabs cannot fit. Material notes that horizontal scrolling meets accessibility requirements, since tabs widen to fit their labels. The row scrolls to the tab the keyboard focuses, and has no scroll buttons. See Scrollable tabs.
Focus
- The tabs are one tab stop: Tab moves the focus to the selected tab.
- By default, the arrow keys only move the focus, and Space or Enter selects the focused tab, as Material advises. See Keyboard activation.
- A panel is a tab stop after the tabs when nothing in it can be focused. It shows the focus ring when the keyboard focuses it.
- A disabled tab cannot be focused.
Keyboard navigation
| Keys | Actions |
|---|---|
| Tab | Move the focus to the selected tab, then into its panel |
| Left or Right arrow | Move the focus to the previous or next tab |
| Up or Down arrow | Move the focus to the previous or next tab of a vertical row |
| Home | Move the focus to the first tab |
| End | Move the focus to the last tab |
| Space or Enter | Select the focused tab |
- The arrow keys wrap around, from the last tab to the first and back, and skip a disabled tab.
- With
keyboardActivation="automatic", the arrow keys select the tab they move to. - The left and right arrow keys are reversed in a right-to-left locale, which is set with an
I18nProvider, not withdir.
Labeling elements
- The
TabListis a tab list, eachTaba tab, and eachTabPanela tab panel. To name the row, set anaria-labeloraria-labelledbyon theTabList. - A tab's text names it. Each panel is named by the tab with the same
id. - A tab with an icon alone needs an
aria-label. Material advises a name that says what the tab shows, such as Video format media content for a video camera icon, and a more descriptive one wherever the visible text is ambiguous. - The selected tab reports it with
aria-selected, and a disabled tab witharia-disabled.
Tabs
variant'primary' | 'secondary'Default'primary'Two variants: primary and secondary
primary: Primary tabs are placed at the top of the content pane under an app bar. They display the main content destinations. Primary tabs should be used when just one set of tabs are needed.secondary: Secondary tabs are used within a content area to further separate related content and establish hierarchy. Secondary tabs are necessary when a screen requires more than one level of tabs. These tabs use a simpler style of indicator, but their function is identical to primary tabs. Secondary tabs should always be placed below primary tabs.
Props of Tabs (18)
classNameClassNameOrFunction<TabsRenderProps>Default'react-aria-Tabs'The CSS className for the element. A function may be provided to compute the class based on component state.
idstringThe element's unique identifier. See MDN.
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
isDisabledbooleanWhether the TabList is disabled. Shows that a selection exists, but is not available in that circumstance.
disabledKeysIterable<Key>The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.
onSelectionChange(key: Key) => voidHandler that is called when the selection changes.
orientation'horizontal' | 'vertical'Default'horizontal'The orientation of the tabs.
selectedKeyKeyThe currently selected key in the collection (controlled).
defaultSelectedKeyKeyThe initial selected keys in the collection (uncontrolled).
keyboardActivation'manual' | 'automatic'Default'automatic'Whether tabs are activated automatically on focus or manually.
childrenChildrenOrFunction<T>The children of the component. A function may be provided to alter the children based on component state.
styleCSSProperties | (values: TabsRenderProps & { defaultStyle: CSSProperties; }) => CSSProperties | undefinedThe inline style for the element. A function may be provided to compute the style based on component state.
renderDOMRenderFunction<'div', TabsRenderProps>Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if
<button>is expected, you cannot render an<a>). - Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
- You must render the expected element type (e.g. if
slotstring | nullA slot name for the component. Slots allow the component to receive props from a parent component. An explicit
nullvalue indicates that the local props completely override all props received from a parent.refRef<HTMLDivElement>
Tabs also takes the 70 attributes and events of the element it renders.
TabList
isScrollablebooleanDefaultfalseFixed tabs display all tabs in a set simultaneously. They are best for switching between related content quickly, such as between transportation methods in a map.
When a set of tabs cannot fit on screen, use scrollable tabs. Scrollable tabs can use longer text labels and a larger number of tabs. They are best used for browsing on touch interfaces.
When using scrollable tabs, the first visible tab should be offset by 52dp from the left side of the device for both web and mobile. The width of each tab is defined by the length of its text label.
Props of TabList (11)
classNameClassNameOrFunction<TabListRenderProps>Default'react-aria-TabList'The CSS className for the element. A function may be provided to compute the class based on component state.
styleCSSProperties | (values: TabListRenderProps & { defaultStyle: CSSProperties; }) => CSSProperties | undefinedThe inline style for the element. A function may be provided to compute the style based on component state.
renderDOMRenderFunction<'div', TabListRenderProps>Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if
<button>is expected, you cannot render an<a>). - Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
- You must render the expected element type (e.g. if
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
childrenReactNode | ((item: T) => ReactNode)The contents of the collection.
itemsIterable<T>Item objects in the collection.
dependenciesReadonlyArray<any>Values that should invalidate the item cache when using dynamic collections.
refRef<HTMLDivElement>
TabList also takes the 70 attributes and events of the element it renders.
Tab
Props of Tab (31)
classNameClassNameOrFunction<TabRenderProps>Default'react-aria-Tab'The CSS className for the element. A function may be provided to compute the class based on component state.
idKeyThe unique id of the tab.
isDisabledbooleanWhether the tab is disabled.
styleCSSProperties | (values: TabRenderProps & { defaultStyle: CSSProperties; }) => CSSProperties | undefinedThe inline style for the element. A function may be provided to compute the style based on component state.
childrenChildrenOrFunction<T>The children of the component. A function may be provided to alter the children based on component state.
render(props: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement> | DetailedHTMLProps<LinkWithRequiredHref, HTMLAnchorElement>, renderProps: TabRenderProps) => ReactElement<unknown, string | JSXElementConstructor<any>>Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.
Note: You can check if
'href' in propsin order to tell whether to render an<a>element.Requirements:
- You must render the expected element type (e.g. if
<a>is expected, you cannot render a<button>). - Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
- You must render the expected element type (e.g. if
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
hrefHrefA URL to link to. See MDN.
hrefLangstringHints at the human language of the linked URL. SeeMDN.
targetHTMLAttributeAnchorTargetThe target window for the link. See MDN.
relstringThe relationship between the linked resource and the current page. See MDN.
downloadboolean | stringCauses the browser to download the linked URL. A string may be provided to suggest a file name. See MDN.
pingstringA space-separated list of URLs to ping when the link is followed. See MDN.
referrerPolicy'' | 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url'How much of the referrer to send when following the link. See MDN.
routerOptionsOptions for the configured client side router.
onHoverStart(e: HoverEvent) => voidHandler that is called when a hover interaction starts.
onHoverEnd(e: HoverEvent) => voidHandler that is called when a hover interaction ends.
onHoverChange(isHovering: boolean) => voidHandler that is called when the hover state changes.
onFocus(e: FocusEvent<Target>) => voidHandler that is called when the element receives focus.
onBlur(e: FocusEvent<Target>) => voidHandler that is called when the element loses focus.
onFocusChange(isFocused: boolean) => voidHandler that is called when the element's focus status changes.
onPress(e: PressEvent) => voidHandler that is called when the press is released over the target.
onPressStart(e: PressEvent) => voidHandler that is called when a press interaction starts.
onPressEnd(e: PressEvent) => voidHandler that is called when a press interaction ends, either over the target or when the pointer leaves the target.
onPressChange(isPressed: boolean) => voidHandler that is called when the press state changes.
onPressUp(e: PressEvent) => voidHandler that is called when a press is released over the target, regardless of whether it started on the target or not.
onClick(e: MouseEvent<FocusableElement>) => voidNot recommended – use
onPressinstead.onClickis an alias foronPressprovided for compatibility with other libraries.onPressprovides additional event details for non-mouse interactions.refRef<HTMLDivElement>
Tab also takes the 69 attributes and events of the element it renders.
TabPanel
Props of TabPanel (11)
classNameClassNameOrFunction<TabPanelRenderProps>Default'react-aria-TabPanel'The CSS className for the element. A function may be provided to compute the class based on component state.
shouldForceMountbooleanDefaultfalseWhether to mount the tab panel in the DOM even when it is not currently selected. Inactive tab panels are inert and cannot be interacted with. They must be styled appropriately so this is clear to the user visually.
idKeyThe unique id of the tab.
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
childrenChildrenOrFunction<T>The children of the component. A function may be provided to alter the children based on component state.
styleCSSProperties | (values: TabPanelRenderProps & { defaultStyle: CSSProperties; }) => CSSProperties | undefinedThe inline style for the element. A function may be provided to compute the style based on component state.
renderDOMRenderFunction<'div', TabPanelRenderProps>Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if
<button>is expected, you cannot render an<a>). - Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
- You must render the expected element type (e.g. if
refRef<HTMLDivElement>
TabPanel also takes the 70 attributes and events of the element it renders.