tabs-more-button
v2.0.0
Published
A lightweight library for making tabbed interfaces responsive by hiding overflow tabs while keeping the active tab visible.
Downloads
77
Maintainers
Readme
tabs-more-button
tabs-more-button
is a lightweight library designed to enhance your tabbed interfaces by making them responsive. This package does not create or manage tabs, but it intelligently hides overflow tabs while ensuring that the active tab remains visible. Ideal for scenarios where space is limited
Features
Responsive
Vertical
supportrtl
supportFlexible style
High performance
Installation
$ npm install tabs-more-button --save
or
$ yarn add tabs-more-button
If you need to directly include script in your html, use the following links :
<script src="https://unpkg.com/tabs-more-button@latest/dist/tabs-more-button.min.js"></script>
Minimal Usage
html :
<div id="container">
<ul id="tablist" style="display:inline-flex;">
<li>Tab 0</li>
<li>Tab 1</li>
<li>Tab 2</li>
<li>Tab 3</li>
<li style="color:red;">Active Tab 4</li>
<li>Tab 5</li>
<li>Tab 6</li>
</ul>
<button id="view-more-button">more</button>
</div>
js :
import tabsMoreButton from 'tabs-more-button';
const options = {
buttonElement: document.getElementById('view-more-button'),
containerElement: document.getElementById('container'),
tablistElement: document.getElementById('tablist'),
};
const instance = new tabsMoreButton(options);
let hiddenTabs = instance.resize(4 /*selectedTabIndex*/);
addEventListener('resize', () => {
hiddenTabs = instance.resize(4 /*selectedTabIndex*/);
});
document.getElementById('view-more-button').addEventListener('click', () => console.table(hiddenTabs));
Rules
view more
button is required to display the hidden tabs and should be next sibling element ofTablist
elementtabs
andview more
button should be kept on same lineShould not be any gap between
view more
button andTablist
options
buttonElement
- type :
HtmlELement
- description :
view more
button
- type :
containerElement
- type :
HtmlELement
- description : parent element of
view more
button andTablist
element
- type :
tablistElement
- type :
HtmlELement
- description : the
Tablist
element
- type :
tabDisplay?
- type :
string
- description :
display
value for eachtab
element - default value :
inline-flex
- type :
containerDisplay?
- type :
"flex"
|"block"
- description :
display
value forcontainerElement
- default value :
flex
- type :
instance methods
resize
- type :
function
- description : makes tabs responsive by hiding
overflow tabs
exceptactive tab
- arguments :
- selectedTabIndex :
- type :
Number
- description : index of active tab element in the tablist element
- type :
- direction? :
- type :
"ltr" | "rtl"
- description : direction value of
tablist
element - default value :
"ltr"
- type :
- isVertical? :
- type :
Boolean
- description :
true
meanstablist
element is vertical - default value :
false
- type :
- selectedTabIndex :
- return :
- type :
Array<{ el: HTMLElement, index: Number }>
- description : array of hidden tabs data
- type :
- type :
Test
$ npm run test
License
MIT