react-tabs-scrollable
a simple react scrollable tabs with a lot of additional features and with fully supporting of RTL mode

Install
npm install --save react-tabs-scrollable
yarn add react-tabs-scrollable
Demo
Features
- Easy to start with it takes you less than minute to start it up!
- It has many features and so easy to customize
- Fully support for RTL (actually the reason why I built this component is because RTL)
- Fully accessible
- You can control in literally everything inside it
- Small size 8k and 3.1k gzipped
- Great to use in navigation , menus and lists or any proper use for tabs
- Easy to style , you have the css file so you can edit it as you would like
- And much more ..
Usage
import React from 'react'
import { Tabs, Tab } from 'react-tabs-scrollable'
import 'react-tabs-scrollable/dist/rts.css'
const SimpleTabs = () => {
const [activeTab, setActiveTab] = React.useState(1)
const onTabClick = (e, index) => {
console.log(e)
setActiveTab(index)
}
return (
<Tabs activeTab={activeTab} onTabClick={onTabClick}>
{/* generating an array to loop through it */}
{[...Array(20).keys()].map((item) => (
<Tab key={item}>Tab {item}</Tab>
))}
</Tabs>
)
}
export default SimpleTabs
Full example with all features
<Tabs
activeTab={activeTab}
onTabClick={(val) => console.log(val)}
action={tabRef}
isRTL={false}
didReachEnd={(val) => console.log(val)}
didReachStart={(val) => console.log(val)}
tabsScrollAmount={3}
animationDuration={300}
navBtnCLickAnimationDuration={300}
selectedAnimationDuration={300}
rightBtnIcon={'>'}
leftBtnIcon={'<'}
hideNavBtns={false}
hideNavBtnsOnMobile={true}
showTabsScroll={false}
navBtnsIconColor={'HEX'}
selectedTabCoordinates={(val) => console.log(val)}
>
<Tab>item </Tab>
{[...Array(20).keys()].map((tab) => (
<Tab key={tab}>Tab {tab}</Tab>
))}
</Tabs>
API
Name | Default | Type | Description |
activeTab* | - | integer | the selected tab value which must be passed to the commponent |
onTabClick* | - | function | function(event, value) => void callback function fires on tab click. It has two props, the first on is the event object the second on is the selected tab value |
action | - | ref | react ref fired when the component mounts. It's useful if you want to some functionalities programmatically. It supports 4 function :
onLeftBtnClick ,onRightBtnClick, goToStart, goToEnd
onLeftBtnClick : to control the left btn click and use your own navigation button. you can call it by so ref.onLeftBtnClick()
onRightBtnClick : to control the right btn click and use your own navigation button. you can call it by so ref.onRightBtnClick()
goToStart : to control the tabs to go to the start of the tabs container. you can call it by so ref.goToStart()
goToEnd : to control the tabs to go to the end of the tabs container. you can call it by so ref.goToEnd()
|
isRTL | false | boolean | sets if the direction of the tabs is RTL or not |
didReachEnd | - | function | sets if the tabs reached the end point of the container didReachEnd={(val) => console.log(val)} |
didReachStart | - | function | sets if the tabs reached the start point of the container didReachStart={(val) => console.log(val)} |
tabsScrollAmount | 3 | string | integer | sets how many tabs you want to scroll on every move tabsScrollAmount={3} |
animationDuration | 300s | integer | sets the animation duration of the scroll when you click on the navigation buttons
note : this will overwirte the animationDuration value animationDuration={300} |
navBtnCLickAnimationDuration | 300s | integer | sets the animation of the scroll when you click on the navigation buttons
note : this will overwirte the animationDuration value navBtnCLickAnimationDuration={300} |
selectedAnimationDuration | 300s | integer | sets the animation of the scroll when you click on a tab that is out of the view
note : this will overwirte the animationDuration value selectedAnimationDuration={300} |
rightBtnIcon | feather arrow-right svg icon | string | jsx | sets the right navitgation button icon rightBtnIcon={'>'} |
leftBtnIcon | feather arrow-left svg icon | string | jsx | sets the left navitgation button icon leftBtnIcon={'>'} |
hideNavBtns | false | boolean | hides the navigantion button hideNavBtns={false} |
hideNavBtnsOnMobile | true | boolean | hides the navigation buttons on mobile devices |
showTabsScroll | false | boolean | shows the scroll of the tabsn |
selectedTabCoordinates | - | function | gets the coordinates of the selected tab
returns object of the width and the scrollLeft of the selected tab
be careful when you use state with this function it will be triggered on every scroll movement and when the app rerenders selectedTabCoordinates={(val) => console.log(val)}
// val returns {width : float , left : float}
// the left turns into right when isRTL={true} |
you can see all the examples in the Demo
please let me see your reviews and if there're any features you want me to add to them
License
MIT © Mohammed Aliwi