@leafygreen-ui/tabs v11.1.15
Tabs
View on MongoDB.design
Installation
Yarn
yarn add @leafygreen-ui/tabs
NPM
npm install @leafygreen-ui/tabs
Example
import { Tabs, Tab } from '@leafygreen-ui/tabs';
const [selected, setSelected] = useState(0)
<Tabs setSelected={setSelected} selected={selected}>
<Tab name="Tab One">Tab Content One</Tab>
<Tab name="Tab Two">Tab Content Two</Tab>
<Tab name="Tab Three">Tab Content Three</Tab>
</Tabs>
Output HTML
<div>
<div class="leafygreen-ui-4furr2" role="tablist">
<button
class="leafygreen-ui-17lvitv"
role="tab"
aria-controls="tab-0"
aria-selected="true"
tabindex="0"
>
Tab One
</button>
<button
class="leafygreen-ui-6uqhxy"
role="tab"
aria-controls="tab-1"
aria-selected="false"
tabindex="-1"
>
Tab Two
</button>
<button
class="leafygreen-ui-6uqhxy"
role="tab"
aria-controls="tab-2"
aria-selected="false"
tabindex="-1"
>
Tab Three
</button>
</div>
<div class="leafygreen-ui-xh3r7y">
<div class="leafygreen-ui-11283ir"></div>
</div>
<div
aria-disabled="false"
aria-selected="true"
aria-controls="tab-0"
role="tabpanel"
>
Tab Content One
</div>
</div>
Properties
Prop | Type | Description | Default |
---|---|---|---|
selected | number | Sets the selected tab. If selected is undefined, the <Tabs /> component will behave as an uncontrolled component. | |
setSelected | function | A callback that receives the index of the tab a user is switching to when clicking, or via keyboard navigation. Usually this is used to set the selected prop to the correct index. The function is only invoked if the selected prop is set. | |
as | React.ElementType | Sets the root element of all <Tab /> components in <Tabs /> . For example, setting as to Link will render each tab as a <Link /> component rather than as a button. | button |
className | string | Adds a className to the root element. | |
children | node | <Tab /> components that will be supplied to <Tabs /> component. | |
darkMode | boolean | Determines whether or not the component will appear in DarkMode | false |
baseFontSize | 13 , 16 | Determines font-size for Tabs Component | 13 |
Any other properties supplied will be spread on the root element.
Tab
Properties
Prop | Type | Description | Default |
---|---|---|---|
name (Required) | string , ReactNode | String that will appear in the list of tabs. | |
disabled | boolean | Indicates whether or not the <Tab /> can be clicked by a user. | false |
default | boolean | Should be supplied when using the uncontrolled <Tabs /> component. This determines which tab will be active by default. | |
className | string | Adds a className to the root element. | |
href | string | Destination when Tab's name in the list should be rendered as an a tag. | |
to | string | Destination when Tab's name in the list should be rendered as a Link tag. | |
children | node | Content that appears inside the <Tab /> component | |
... | native attributes of component passed to as prop | Any other props will be spread on the root element |
Reference
Usage with NextJS Link components
Tabs may not render with the correct tags or styles if the NextJS Link component is passed to the as
prop directly, given how NextJS handles default rendering of the component based on the href
prop. To work around this, pass the NextJS Link as shown below.
import NextLink from 'next/link';
function Linker({ href, children, ...props }) {
return (
<NextLink href={href}>
<a {...props}>
{children}
</a>
</NextLink>
);
}
<Tabs aria-label="Profile Sections" as={Linker}>
...
</Tabs>
25 days ago
1 month ago
7 months ago
8 months ago
6 months ago
7 months ago
10 months ago
10 months ago
9 months ago
9 months ago
10 months ago
8 months ago
9 months ago
9 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
11 months ago
11 months ago
11 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago