Tabs API
Import
Section titled “Import”Cimpress UI exports four tabs-related components:
Tabs: container component that displays a list of organizational tabs.TabList: renders a list of tabs withinTabs.Tab: renders a single tab withinTabs.TabPanels: renders a list of tab panels withinTabs.TabPanel: renders a single tab panel withinTabs.LinkTabs: container component that displays a list of navigational tabs.LinkTab: renders a single tab withinLinkTabs.
import { Tabs, TabList, Tab, TabPanels, TabPanel, LinkTabs, LinkTab } from '@cimpress-ui/react';Controlled/uncontrolled usage
Section titled “Controlled/uncontrolled usage”This component can be used in a controlled or uncontrolled way.
In the controlled way, this component doesn’t maintain its own internal state, and its value is provided by the parent component. Use the controlled way when you need to be able to change the state of this component in other parts of your application.
In the uncontrolled way, this component maintains its own internal state, and can optionally notify the parent component when its internal state changes. Use the uncontrolled way when you don’t need to change the state of this component in other parts of your application.
Organizational tabs
Section titled “Organizational tabs”Controlled
Uncontrolled
import { type Key, Stack, Tabs, Tab, TabList, TabPanel, TabPanels, Text } from '@cimpress-ui/react';import { useState } from 'react';
export default function Demo() { const [selectedKey, setSelectedKey] = useState<Key | null>('tab-2');
return ( <Stack gap={32}> <Stack gap={16}> <Text as="h2" variant="title-4"> Controlled </Text>
<Tabs aria-label="Tabs example (controlled)" selectedKey={selectedKey} onSelectionChange={setSelectedKey}> <TabList> <Tab id="tab-1">Tab 1</Tab> <Tab id="tab-2">Tab 2</Tab> <Tab id="tab-3">Tab 3</Tab> </TabList> <TabPanels> <TabPanel id="tab-1">Content for tab 1</TabPanel> <TabPanel id="tab-2">Content for tab 2</TabPanel> <TabPanel id="tab-3">Content for tab 3</TabPanel> </TabPanels> </Tabs> </Stack>
<Stack gap={16}> <Text as="h2" variant="title-4"> Uncontrolled </Text>
<Tabs aria-label="Tabs example (uncontrolled)" defaultSelectedKey="tab-2"> <TabList> <Tab id="tab-1">Tab 1</Tab> <Tab id="tab-2">Tab 2</Tab> <Tab id="tab-3">Tab 3</Tab> </TabList> <TabPanels> <TabPanel id="tab-1">Content for tab 1</TabPanel> <TabPanel id="tab-2">Content for tab 2</TabPanel> <TabPanel id="tab-3">Content for tab 3</TabPanel> </TabPanels> </Tabs> </Stack> </Stack> );}Navigational tabs
Section titled “Navigational tabs”Controlled
Uncontrolled
import { type Href, LinkTabs, LinkTab, Stack, Text } from '@cimpress-ui/react';import { useState } from 'react';
export default function Demo() { const [currentHref, setCurrentHref] = useState<Href | null>('#tab-2');
return ( <Stack gap={32}> <Stack gap={16}> <Text as="h2" variant="title-4"> Controlled </Text>
<LinkTabs aria-label="Link tabs example (controlled)" currentHref={currentHref} onHrefChange={setCurrentHref}> <LinkTab href="#tab-1">Tab 1</LinkTab> <LinkTab href="#tab-2">Tab 2</LinkTab> <LinkTab href="#tab-3">Tab 3</LinkTab> </LinkTabs> </Stack>
<Stack gap={16}> <Text as="h2" variant="title-4"> Uncontrolled </Text>
<LinkTabs aria-label="Link tabs example (uncontrolled)" defaultHref="#tab-2"> <LinkTab href="#tab-1">Tab 1</LinkTab> <LinkTab href="#tab-2">Tab 2</LinkTab> <LinkTab href="#tab-3">Tab 3</LinkTab> </LinkTabs> </Stack> </Stack> );}Accessibility notes
Section titled “Accessibility notes”Tabs follows the ARIA tabs pattern. See the linked page for a list of available keyboard interactions.
The Tabs tab list is a single tab stop within the page’s tab order. Use the Tab key to navigate to the list, and the arrow keys to navigate between tabs within the list.
Tab can be activated by pressing Enter or Space, similar to a native HTML button.
LinkTab can be activated by pressing Enter, similar to a native HTML link.
Tabs should have an aria-label prop defined to identify the purpose of the tabs to assistive technologies. See our accessibility guide for more details.
LinkTabs renders a navigation landmark, and requires a textual label to identify itself to assistive technologies. See our accessibility guide for more details.
Collections
Section titled “Collections”Tabs is a collection component. See our collection components guide to learn how to work with collections.
API reference
Section titled “API reference”Organizes content into multiple sections that users can switch between.
- Ref<HTMLDivElement>
-
The
reftype for this component.
TabsProps
- ReactNode
children *
Section titled “ children * ” -
The children of the
<Tabs>element. Should include<TabList>and<TabPanels>elements. - string
-
The element's unique identifier. See MDN.
- boolean
data-cim-style-root
Section titled “ data-cim-style-root ” -
Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- string
UNSAFE_className
Section titled “ UNSAFE_className ” -
Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- CSSProperties
UNSAFE_style
Section titled “ UNSAFE_style ” -
Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
- string
aria-label
Section titled “ aria-label ” -
Defines a string value that labels the current element.
- string
aria-labelledby
Section titled “ aria-labelledby ” -
Identifies the element (or elements) that labels the current element.
- string
aria-describedby
Section titled “ aria-describedby ” -
Identifies the element (or elements) that describes the object.
- string
aria-details
Section titled “ aria-details ” -
Identifies the element (or elements) that provide a detailed, extended description for the object.
- Iterable<Key, any, any>
disabledKeys
Section titled “ disabledKeys ” -
The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.
- Key | null
selectedKey
Section titled “ selectedKey ” -
The currently selected key in the collection (controlled).
- Key
defaultSelectedKey
Section titled “ defaultSelectedKey ” -
The initial selected key in the collection (uncontrolled).
- (key: Key) => void
onSelectionChange
Section titled “ onSelectionChange ” -
Handler that is called when the selection changes.
StyleProps
- Responsive<Spacing | "auto">
margin
Section titled “ margin ” -
The amount of margin applied to all edges of this component.
- Responsive<Spacing | "auto">
marginX
Section titled “ marginX ” -
The amount of margin applied to the left and right edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginY
Section titled “ marginY ” -
The amount of margin applied to the top and bottom edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginTop
Section titled “ marginTop ” -
The amount of margin applied to the top edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginRight
Section titled “ marginRight ” -
The amount of margin applied to the right edge of this component. Takes priority over
marginXandmargin. - Responsive<Spacing | "auto">
marginBottom
Section titled “ marginBottom ” -
The amount of margin applied to the bottom edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginLeft
Section titled “ marginLeft ” -
The amount of margin applied to the left edge of this component. Takes priority over
marginXandmargin.
TabList
Section titled “TabList”Renders a collection of Tab components within Tabs.
TabListProps<T extends CollectionItem>
- ReactNode | ((item: T) => ReactNode)
children
Section titled “ children ” -
The contents of the collection.
- Iterable<T, any, any>
items
Section titled “ items ” -
The items to display in the collection.
Renders a single tab within TabList.
TabProps
- StringLikeChildren
children *
Section titled “ children * ” -
The text to display as the tab title.
- Key
-
The unique ID of the tab.
- ReactNode
iconStart
Section titled “ iconStart ” -
An icon displayed before the tab title.
- ReactNode
badge
Section titled “ badge ” -
A badge displayed after the tab title.
- (e: HoverEvent) => void
onHoverStart
Section titled “ onHoverStart ” -
Handler that is called when a hover interaction starts.
- (e: HoverEvent) => void
onHoverEnd
Section titled “ onHoverEnd ” -
Handler that is called when a hover interaction ends.
- boolean
isDisabled
Section titled “ isDisabled ” -
Whether the tab is disabled.
TabPanels
Section titled “TabPanels”Renders a collection of TabPanel components within Tabs.
TabPanelsProps<T extends CollectionItem>
- ReactNode | ((item: T) => ReactNode)
children
Section titled “ children ” -
The contents of the collection.
- Iterable<T, any, any>
items
Section titled “ items ” -
The items to display in the collection.
TabPanel
Section titled “TabPanel”Renders a single tab panel within TabPanels.
TabPanelProps
- ReactNode
children *
Section titled “ children * ” -
The content to display in the tab panel.
- Key
-
The unique id of the associated tab.
LinkTabs
Section titled “LinkTabs”Displays a list of tabs to help users navigate through a website.
- Ref<HTMLDivElement>
-
The
reftype for this component.
LinkTabsProps
- ReactNode
children *
Section titled “ children * ” -
Link tabs belonging to the group.
- boolean
isDisabled
Section titled “ isDisabled ” -
Whether the link tabs are disabled.
- string | null
currentHref
Section titled “ currentHref ” -
The currently selected key in the collection (controlled).
- string | null
defaultHref
Section titled “ defaultHref ” -
The initial selected key in the collection (uncontrolled).
- (href: string | null) => void
onHrefChange
Section titled “ onHrefChange ” -
Handler that is called when the selection changes.
- string
-
The element's unique identifier. See MDN.
- boolean
data-cim-style-root
Section titled “ data-cim-style-root ” -
Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- string
UNSAFE_className
Section titled “ UNSAFE_className ” -
Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- CSSProperties
UNSAFE_style
Section titled “ UNSAFE_style ” -
Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
- string
aria-label
Section titled “ aria-label ” -
Defines a string value that labels the current element.
- string
aria-labelledby
Section titled “ aria-labelledby ” -
Identifies the element (or elements) that labels the current element.
- string
aria-describedby
Section titled “ aria-describedby ” -
Identifies the element (or elements) that describes the object.
- string
aria-details
Section titled “ aria-details ” -
Identifies the element (or elements) that provide a detailed, extended description for the object.
StyleProps
- Responsive<Spacing | "auto">
margin
Section titled “ margin ” -
The amount of margin applied to all edges of this component.
- Responsive<Spacing | "auto">
marginX
Section titled “ marginX ” -
The amount of margin applied to the left and right edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginY
Section titled “ marginY ” -
The amount of margin applied to the top and bottom edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginTop
Section titled “ marginTop ” -
The amount of margin applied to the top edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginRight
Section titled “ marginRight ” -
The amount of margin applied to the right edge of this component. Takes priority over
marginXandmargin. - Responsive<Spacing | "auto">
marginBottom
Section titled “ marginBottom ” -
The amount of margin applied to the bottom edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginLeft
Section titled “ marginLeft ” -
The amount of margin applied to the left edge of this component. Takes priority over
marginXandmargin.
LinkTab
Section titled “LinkTab”Renders a single tab within LinkTabs.
LinkTabProps
- StringLikeChildren
children *
Section titled “ children * ” -
The text to display as the tab title.
- string
href *
Section titled “ href * ” -
A URL to link to.
- ReactNode
iconStart
Section titled “ iconStart ” -
An icon displayed before the tab title.
- ReactNode
badge
Section titled “ badge ” -
A badge displayed after the tab title.
- boolean
data-cim-style-root
Section titled “ data-cim-style-root ” -
Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- string
UNSAFE_className
Section titled “ UNSAFE_className ” -
Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- CSSProperties
UNSAFE_style
Section titled “ UNSAFE_style ” -
Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
- undefined
routerOptions
Section titled “ routerOptions ” -
Options for the configured client side router.
- boolean
isDisabled
Section titled “ isDisabled ” -
Whether the link is disabled.
- string
hrefLang
Section titled “ hrefLang ” -
Hints at the human language of the linked URL. SeeMDN.
- HTMLAttributeAnchorTarget
target
Section titled “ target ” -
The target window for the link. See MDN.
- string
-
The relationship between the linked resource and the current page. See MDN.
- string | boolean
download
Section titled “ download ” -
Causes the browser to download the linked URL. A string may be provided to suggest a file name. See MDN.
- string
-
A space-separated list of URLs to ping when the link is followed. See MDN.
- HTMLAttributeReferrerPolicy
referrerPolicy
Section titled “ referrerPolicy ” -
How much of the referrer to send when following the link. See MDN.
- (e: HoverEvent) => void
onHoverStart
Section titled “ onHoverStart ” -
Handler that is called when a hover interaction starts.
- (e: HoverEvent) => void
onHoverEnd
Section titled “ onHoverEnd ” -
Handler that is called when a hover interaction ends.