4.4.3 • Published 3 years ago

react-responsive-tabs v4.4.3

Weekly downloads
6,077
License
MIT
Repository
github
Last release
3 years ago

React responsive tabs

Live demo

Your feedback is highly appreciated!

Please, file an issue if something went wrong or let me know via Twitter @maslianok

Responsive

  • Hide tabs under the 'Show more' option when they don't fit into the screen
  • Transform tabs into the accordion when the wrapper width reaches the transformWidth value

Responsive tabs

Accessible

The component outputs HTML code that follows accessibility principles (aka WAI-ARIA) and uses ARIA attributes such as role, aria-selected, aria-controls, aria-labeledby etc.

Accessible tabs

Fast

We are using react-resize-detector. No timers. Just pure event-based element resize detection.

Installation

npm install react-responsive-tabs

Demo

Live demo

Local demo

# 1. clone the repository
git clone https://github.com/maslianok/react-responsive-tabs.git

# 2. Install react-responsive-tabs dependencies. You must do it because we use raw library code in the example
cd react-responsive-tabs
npm install

# 3. Install dependencies to run the example
cd examples
npm install

# 4. Finally run the example
npm start

Example

import React, { Component } from 'react';
import { render } from 'react-dom';
import Tabs from 'react-responsive-tabs';

// IMPORTANT you need to include the default styles
import 'react-responsive-tabs/styles.css';

const presidents = [
  { name: 'George Washington', biography: '...' },
  { name: 'Theodore Roosevelt', biography: '...' },
];

function getTabs() {
  return presidents.map((president, index) => ({
    title: president.name,
    getContent: () => president.biography,
    /* Optional parameters */
    key: index,
    tabClassName: 'tab',
    panelClassName: 'panel',
  }));
}

const App = () => <Tabs items={getTabs()} />;

render(<App />, document.getElementById('root'));

API

All entities listed below should be used as props to the Tabs component.

PropTypeDescriptionDefault
itemsArrayTabs data[]
beforeChangeFunctionFires right before a tab changes. Return false to prevent the tab changeundefined
onChangeFunctiononChange callbackundefined
selectedTabKeyNumber/StringSelected tabundefined
showMoreBoolWhether to show Show more or nottrue
showMoreLabelString/NodeShow more tab name...
transformBoolTransform to accordion when the wrapper width is less than transformWidth.true
transformWidthNumberTransform width.800
unmountOnExitBoolWhether to unmount inactive tabs from DOM tree or nottrue
tabsWrapperClassStringWrapper classundefined
tabClassNameStringTab classundefined
panelClassNameStringTab panel classundefined
allowRemoveBoolAllows tabs removal.false
removeActiveOnlyBoolOnly active tab has removal optionfalse
showInkBarBoolAdd MaterialUI InkBar effectfalse
uidanyAn optional external id. The component rerenders when it changesundefined

License

MIT

4.4.3

3 years ago

4.4.2

3 years ago

4.4.1

3 years ago

4.4.0

3 years ago

4.3.0

3 years ago

4.2.1

3 years ago

4.2.0

3 years ago

4.1.1

4 years ago

4.1.0

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.3.1

4 years ago

3.3.0

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.0

6 years ago

2.1.0

6 years ago

2.0.2

6 years ago

2.0.0

6 years ago

1.3.0

6 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.0.1

7 years ago

0.9.0

7 years ago

0.8.1

7 years ago

0.8.0

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.5.6

7 years ago

0.5.5

7 years ago

0.5.4

8 years ago

0.5.3

8 years ago

0.5.2

8 years ago

0.5.1

8 years ago

0.5.0

8 years ago

0.4.9

8 years ago

0.4.8

8 years ago

0.4.7

8 years ago

0.4.6

8 years ago

0.4.5

8 years ago

0.4.4

8 years ago

0.4.3

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago