ndla-tabs
A simple tabs component. Mainly a wrapper for react-tabs.
Installation
$ yarn add --save ndla-tabs
$ npm install ndla-tabs --save
Usage
Styling
/* Your project's main .scss import file */; // with webpack and sass-loader ; // direct reference
Basic example
;;; const Fruits = { const fruitTabs = title: 'Apple' content: <p>An apple a day keeps the doctor away</p> title: 'Orange' <h1>Orange is the </h1> title: 'Banana' content: <BananaComponent /> title: 'Pickle' content: <PickleComponent /> disabled: true // No vegetables allowed! ; return <Tabs tabs=fruitTabs />;};
selectedIndex
prop
Example where selected tab is controlled via ;; { superprops; thisstate = index: 0 ; } { const index = thisstate; return <div> <button onClick= this> Show banana tab </button> <Tabs selectedIndex=index tabs=fruitTabs /> </div> ; }
PropTypes
Props | Type | Required | Description |
---|---|---|---|
tabs | array | * | An array of tabs represented as objects. An tab object requires the following properties: title , content . Property disabled is optional. |
onSelect | func | Is called when a tab is selected. Current index and last index will be passed as parameters. | |
selectedIndex | object | Is the tab to select when rendered. Used when you want to control which tab is rendered from the a parent component. | |
forceRenderTabPanel | bool | Is false by default. Set to true to render all tab's content instead of only selected tab content. |
|
modifier | string | An BEM modifier which is added to all html classes. |
Server side rendering
resetIdCounter should be called on server before render to prevent server and client markup diff. Example:
; ; ReactDOMServer;