1.0.0 • Published 3 years ago

responsivedynamictabs v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

React responsive dynamic tabs

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 responsiveDynamictabs

Example

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

// IMPORTANT you need to include the default styles
import 'responsiveDynamictabs/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