Gathering detailed insights and metrics for react-tabs-scrollable
Gathering detailed insights and metrics for react-tabs-scrollable
Gathering detailed insights and metrics for react-tabs-scrollable
Gathering detailed insights and metrics for react-tabs-scrollable
react-navigation-tabs
Tab Navigation components for React Navigation
react-smooth-tabs
https://react-scrollable-tabs.vercel.app/
react-scrollable-tabs
Builds out a scrollable tabs component
react-native-scrollable-tabs
This is probably my favorite navigation pattern on Android, I wish it were more common on iOS! This is a very simple JavaScript-only implementation of it for React Native. For more information about how the animations behind this work, check out the Rebou
npm install react-tabs-scrollable
Typescript
Module System
Node Version
NPM Version
78
Supply Chain
93.6
Quality
77.9
Maintenance
100
Vulnerability
100
License
Total Downloads
468,884
Last Day
199
Last Week
5,274
Last Month
22,784
Last Year
258,249
Minified
Minified + Gzipped
Latest Version
2.0.8
Package Id
react-tabs-scrollable@2.0.8
Unpacked Size
230.44 kB
Size
61.32 kB
File Count
22
NPM Version
10.8.2
Node Version
20.16.0
Published on
Jan 16, 2025
Cumulative downloads
Total Downloads
Last Day
0%
199
Compared to previous day
Last Week
8.3%
5,274
Compared to previous week
Last Month
-22.6%
22,784
Compared to previous month
Last Year
59.5%
258,249
Compared to previous year
a simple react scrollable tabs with a lot of additional features and with fully supporting of RTL mode
1npm install --save react-tabs-scrollable@latest 2yarn add react-tabs-scrollable@latest
1npm install --save react-tabs-scrollable@1.0.10 2yarn add react-tabs-scrollable@1.0.10
I rebuild the package from scratch with typescript to avoid the unnecessary bugs and to make it more elegant and easy to use with the typescript auto-complete.
Note: this's my first time using typescript so expect many bugs with types since i was interfering a lot of types to any, and because I dont have the proper internet, I couldnt search well for them -_-. But overall I think everything works fine!.
I deleted the unnecessary code and made it more readable and clean.
I deleted selectedTabCoordinates
and replaced it with getTabsBoundingClientRects
function that returns DOMRect object for the tabsContainer
and tab
, and it's way performant comparing to the old selectedTabCoordinates
, it just runs when the scroll stops and when you switch to RTL.
I renamed the two action onRightBtnClick
and onLeftBtnClick
to onRightNavBtnClick
and onLeftNavBtnClick
I made the API and the enternals of the component more exposed to the developers who wants to use it (Please see the API table below to see all the new props), since I added about 15 new props including refs to all the elements inside the pacakge, and I added custom styles to style it as you want.
I added new features to make the component more compatible with my new package react-kfc-menu
such as mode
prop that controls the behavior of the selected tab scroll, now you can change the whole behavior of it with the new 4 modes I've added to it.
I added <TabScreen />
component if you want to use tab panels with the tabs.
I'm planning to add Swipeable component to make the TabScreens more interactive with drag and touch events on both, Desktop and mobile.
Please If you faced any bugs feel free to open an issue.
1import React from "react"; 2import { Tabs, Tab } from "react-tabs-scrollable"; 3import "react-tabs-scrollable/dist/rts.css"; 4 5const SimpleTabs = () => { 6 // define state with initial value to let the tabs start with that value 7 const [activeTab, setActiveTab] = React.useState(1); 8 9 // define a onClick function to bind the value on tab click 10 const onTabClick = (e, index) => { 11 console.log(e); 12 setActiveTab(index); 13 }; 14 15 return ( 16 <> 17 <Tabs activeTab={activeTab} onTabClick={onTabClick}> 18 {/* generating an array to loop through it */} 19 {[...Array(20).keys()].map((item) => ( 20 <Tab key={item}>Tab {item}</Tab> 21 ))} 22 </Tabs> 23 </> 24 ); 25}; 26 27export default SimpleTabs;
1import React from "react"; 2import { Tabs, Tab } from "react-tabs-scrollable"; 3import "react-tabs-scrollable/dist/rts.css"; 4 5const SimpleTabs = () => { 6 // define state with initial value to let the tabs start with that value 7 const [activeTab, setActiveTab] = React.useState(1); 8 9 // define a onClick function to bind the value on tab click 10 const onTabClick = (e, index) => { 11 console.log(e); 12 setActiveTab(index); 13 }; 14 const tabsArray = [...Array(20).keys()]; 15 return ( 16 <> 17 <Tabs activeTab={activeTab} onTabClick={onTabClick}> 18 {/* generating an array to loop through it */} 19 {tabsArray.map((item) => ( 20 <Tab key={item}>Tab {item}</Tab> 21 ))} 22 </Tabs> 23 24 {tabsArray.map((item) => ( 25 <TabScreen 26 key={item} 27 activeTab={activeTab} 28 index={item} 29 // You can add animation with adding a custom class 30 className="some-animation-class" 31 > 32 TabScreen {item} 33 </TabScreen> 34 ))} 35 </> 36 ); 37}; 38 39export default SimpleTabs;
1<Tabs 2 // the selected tab state which must be passed to the commponent 3 activeTab={activeTab} 4 // tab on click function 5 // it has two props 6 // first one is event object 7 // second one is the index of the selected tab 8 onTabClick={(val) => console.log(val)} 9 // this prop returns a group of events to control the tabs such as onLeftNavBtnClick , onRightNavBtnClick to control the tabs 10 // you should pass here a ref to get the required functionality 11 action={tabRef} 12 // sets if the direction of the page is RTL or not 13 // default false 14 isRTL={false} 15 // sets if the tabs reached the end point of the tab container 16 // function 17 didReachEnd={(val) => console.log(val)} 18 // sets if the tabs reached the start point container 19 // function 20 didReachStart={(val) => console.log(val)} 21 // sets how many tabs you want to scroll on every move 22 // default 3 tabs on each navigation button click 23 tabsScrollAmount={3} 24 // sets the general animation duration when you click on the navigation buttons and when you click out the tabs view 25 // this option will disable navBtnCLickAnimationDuration and selectedAnimationDuration 26 // default 300s 27 animationDuration={300} 28 // sets the animation of the scroll when you click on the navigation buttons 29 // note : this will overwirte the animationDuration value 30 // default 300s 31 navBtnCLickAnimationDuration={300} 32 // sets the animation of the scroll when you click on a tab that is out of the view 33 // note : this will overwirte the animationDuration value 34 // default 300s 35 selectedAnimationDuration={300} 36 // sets the right navitgation vutton icon 37 // default feather arrow-right svg icon 38 // you can pass jsx here or just a string 39 rightBtnIcon={">"} 40 // sets the left navitgation button icon 41 // default feather arrow-left svg icon 42 // you can pass jsx here or just a string 43 leftBtnIcon={"<"} 44 //hides the navigantion button 45 // default false 46 hideNavBtns={false} 47 // hides the navigation buttons on mobile devices 48 // default true 49 hideNavBtnsOnMobile={true} 50 // shows the scroll of the tabs 51 // default false 52 showTabsScroll={false} 53 // returns the DOMRect object of the selected tab and the tabs container 54 getTabsBoundingClientRects={(val) => console.log(val)} 55 // A react ref that can be used to control the tabs programmatically 56 // Check the API section to understand more 57 action={ref} 58 // You can change the behaviour of the selected tab scroll by changing the option of it, whether to move it to center, start, end or to center but if the selected tab is in the view. 59 // Check the API section to understand more or you can play with it to understand the idea 60 mode="scrollSelectedToCenterFromView" 61 // changes the underline HTML element 62 navBtnAs="div" 63 // These props sets the className of their elements 64 tabsContainerClassName="" 65 tabsUpperContainerClassName="" 66 tabsContainerClassName="" 67 leftNavBtnClassName="" 68 rightNavBtnClassName="" 69 navBtnClassName="" 70 navBtnContainerClassName="" 71 // Sets the style of these element 72 navBtnStyle={{}} 73 tabsContainerStyle={{}} 74 tabsUpperContainerStyle={{}} 75 // You can get the ref of these elements 76 tabsContainerRef={ref} 77 tabRef={ref} 78 leftNavBtnRef={ref} 79 rightNavBtnRef={ref} 80> 81 <Tab>item </Tab> 82 {[...Array(20).keys()].map((tab) => ( 83 <Tab key={tab}>Tab {tab}</Tab> 84 ))} 85</Tabs>
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 |
mode | scrollSelectedToStart | string | it controls the behavoiur of the selected tab whether to move it to start | center | end | center if the tab is in the view.
it contains 3 modes:
|
action | - | ref | react ref fires when the component mounts. It's useful if you want to control some functionalities programmatically. It supports 4 function : onLeftNavBtnClick ,onRightNavBtnClick, goToStart, goToEnd onLeftNavBtnClick : to control the left btn click and use your own navigation button. you can call it by so ref.current.onLeftNavBtnClick() onRightNavBtnClick : to control the right btn click and use your own navigation button. you can call it by so ref.current.onRightNavBtnClick()
goToStart : to control the tabs to go to the start of the tabs container. you can call it by so ref.current.goToStart() goToEnd : to control the tabs to go to the end of the tabs container. you can call it by so ref.current.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 |
getTabsBoundingClientRects | - | function | returns a callback with the DOMRects object of the selected tab and the tabsContainer. |
tabsContainerRef | - | ref | the tabs container ref object |
tabRef | - | ref | the tabs ref object and it returns an array of all the tab ref |
leftNavBtnRef | - | ref | sets the left navigation btn's ref |
rightNavBtnRef | - | ref | sets the right navigation btn's ref |
navBtnStyle | - | object | sets the navigation btns' style object |
tabsContainerStyle | - | object | Sets tabs container's style object |
tabsUpperContainerStyle | - | object | Sets the tabs upper container's style object |
leftNavBtnClassName | - | string | Sets the left navigation button's className |
rightNavBtnClassName | - | string | Sets the right navigation button's className |
navBtnClassName | - | string | Sets the navigation buttons' className |
navBtnContainerClassName | - | string | Sets the navigation buttons' container className |
tabsUpperContainerClassName | - | string | Sets the upper tabs container's className |
tabsContainerClassName | - | string | Sets the tabs container's className |
navBtnAs | button | string | Sets the HTML element of the navigation buttons |
Name | Default | Type | Description |
tabAs | button | string | You can change the HTML element of the
Tab
Note: Changing the underline element will affect on the accessiblity of the tab
|
style | - | object | sets Tab's style object |
className | - | string | you can pass a custom className to the Tab component |
Name | Default | Type | Description |
activeTab* | - | integer | the selected tab value which must be passed to the commponent |
index* | - | integer | string | the index of the tabscreen which must match the activeTab integer |
as | dov | string |
You can change the HTML element of the
TabScreen
|
style | - | object | sets Tab's style object |
className | - | string | you can pass a custom className to the TabScreen component |
If you liked this project don't forget to see my other projects on NPM and github
Show your support by giving a ⭐. Any feature requests are welcome! Anyone is welcomed to contribute in this project.
Buying me coffee will help me sustain the updates and work on new project for the open-source
Support this project with your organization / company or individual.
No vulnerabilities found.
No security vulnerabilities found.