11.1.15 • Published 25 days ago

@leafygreen-ui/tabs v11.1.15

Weekly downloads
397
License
Apache-2.0
Repository
github
Last release
25 days ago

Tabs

npm (scoped)

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

PropTypeDescriptionDefault
selectednumberSets the selected tab. If selected is undefined, the <Tabs /> component will behave as an uncontrolled component.
setSelectedfunctionA 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.
asReact.ElementTypeSets 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
classNamestringAdds a className to the root element.
childrennode<Tab /> components that will be supplied to <Tabs /> component.
darkModebooleanDetermines whether or not the component will appear in DarkModefalse
baseFontSize13, 16Determines font-size for Tabs Component13

Any other properties supplied will be spread on the root element.

Tab

Properties

PropTypeDescriptionDefault
name (Required)string, ReactNodeString that will appear in the list of tabs.
disabledbooleanIndicates whether or not the <Tab /> can be clicked by a user.false
defaultbooleanShould be supplied when using the uncontrolled <Tabs /> component. This determines which tab will be active by default.
classNamestringAdds a className to the root element.
hrefstringDestination when Tab's name in the list should be rendered as an a tag.
tostringDestination when Tab's name in the list should be rendered as a Link tag.
childrennodeContent that appears inside the <Tab /> component
...native attributes of component passed to as propAny 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>
11.1.15

25 days ago

11.1.14

1 month ago

11.1.11

7 months ago

11.1.10

8 months ago

11.1.13

6 months ago

11.1.12

7 months ago

12.0.0-alpha.1

10 months ago

12.0.0-alpha.0

10 months ago

11.1.5

9 months ago

11.1.6

9 months ago

11.1.4

10 months ago

11.1.9

8 months ago

11.1.7

9 months ago

11.1.8

9 months ago

11.0.10

12 months ago

11.1.1-next.5

12 months ago

11.1.1-next.4

12 months ago

11.1.1-next.7

12 months ago

11.1.1-next.6

12 months ago

11.0.9

12 months ago

11.1.1-next.1

12 months ago

11.1.1-next.0

12 months ago

11.1.1-next.3

12 months ago

11.1.1-next.2

12 months ago

11.1.3

11 months ago

11.1.1

11 months ago

11.1.2

11 months ago

11.1.0

12 months ago

11.0.6

1 year ago

11.0.7

1 year ago

11.0.5

1 year ago

11.0.8

1 year ago

11.0.4

1 year ago

11.0.2

1 year ago

11.0.3

1 year ago

11.0.0

1 year ago

11.0.1

1 year ago

9.2.1

2 years ago

10.0.0

2 years ago

10.0.1

2 years ago

9.1.0

2 years ago

9.2.0

2 years ago

9.1.0-test.0

2 years ago

9.1.0-next.2

2 years ago

9.1.0-next.0

2 years ago

9.1.0-next.1

2 years ago

9.0.2

2 years ago

9.0.1

2 years ago

8.0.0

2 years ago

9.0.0

2 years ago

7.0.1

2 years ago

6.0.3

2 years ago

6.0.2

2 years ago

7.0.0

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

5.1.5

3 years ago

5.1.4

3 years ago

5.1.3

3 years ago

5.1.2

3 years ago

5.1.1

3 years ago

5.1.0

3 years ago

5.0.3

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.0.6

3 years ago

4.0.5

3 years ago

4.0.4

3 years ago

4.0.3

4 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.6

4 years ago

2.1.5

4 years ago

2.1.4

4 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago