Tabs
Installation
yarn add @spark-web/tabs
@spark-web/tabs
Tabs are a set of layered sections of content (known as tab panels) that display one panel of content at a time. Each tab panel has an associated tab element, that when activated, displays the panel. The list of tab elements is arranged along the top edge of the currently displayed panel.
Example
Default Index
By default, users will be shown the first tab. This can be overridden by
providing a defaultIndex
prop. You can also have no tabs active by default
by providing a defaultIndex
of -1
.
Disabled tabs
Individual tabs can be be disabled by providing them with a disabled
prop.
Manual Activation
By default, when a tab has focus, users can cycle through the enabled tabs using
the arrow keys. If activationMode
is set to "manual"
, users can activate a
tab by pressing the Enter
or Space
key when the tab you want to view has
focus.
It is very important for usability that functionality of components behaves in a consistent manor. It is therefore recommended that you do not use the manual activation mode unless you absolutely need it.
Props
Tabs
Prop | Type | Description |
---|---|---|
children | ReactNode: string | number | false | true | {} | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | Children elements to be rendered within the component. Expected to be `TabList` and `TabPanels`. |
activationMode? | "automatic" | "manual" | When automatic, tabs are activated when receiving focus. When manual, tabs are activated when clicked. Default: |
data? | DataAttributeMap | Sets data attributes for the element. |
defaultIndex? | number | The index of the tab that should be active when initially rendered. |
TabList
Prop | Type | Description |
---|---|---|
children | ReactElement<TabProps, string | JSXElementConstructor<any>>[] | Children elements to be rendered within the component. Expected to be more than one `Tab` component. |
data? | DataAttributeMap | Sets data attributes for the element. |
Tab
Prop | Type | Description |
---|---|---|
children | ReactNode: string | number | false | true | {} | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | Children elements to be rendered within the component. |
data? | DataAttributeMap | Sets data attributes for the element. |
disabled? | boolean | When true, prevents the user from interacting with the tab. |
TabPanels
Prop | Type | Description |
---|---|---|
children | ReactElement<TabPanelProps, string | JSXElementConstructor<any>>[] | Children elements to be rendered within the component. Expected to be more than one `TabPanel` component. |
data? | DataAttributeMap | Sets data attributes for the element. |
TabPanel
Prop | Type | Description |
---|---|---|
children | ReactNode: string | number | false | true | {} | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | Children elements to be rendered within the component. |
data? | DataAttributeMap | Sets data attributes for the element. |