Add the ability to get tabs by a relative position.
Made 0 be an invalid position.
This commit is contained in:
parent
f618ab0c4d
commit
6c2ead8edd
2 changed files with 41 additions and 19 deletions
22
index.js
22
index.js
|
@ -86,9 +86,6 @@ class TabGroup extends EventEmitter {
|
|||
|
||||
getTabByPosition (position) {
|
||||
let fromRight = position < 0;
|
||||
if (position === 0) {
|
||||
position = 1;
|
||||
}
|
||||
for (let i in this.tabs) {
|
||||
if (this.tabs[i].getPosition(fromRight) === position) {
|
||||
return this.tabs[i];
|
||||
|
@ -97,6 +94,22 @@ class TabGroup extends EventEmitter {
|
|||
return null;
|
||||
}
|
||||
|
||||
getTabByRelPosition (position) {
|
||||
position = this.getActiveTab().getPosition() + position;
|
||||
if (position <= 0) {
|
||||
return null;
|
||||
}
|
||||
return this.getTabByPosition(position);
|
||||
}
|
||||
|
||||
getNextTab () {
|
||||
return this.getTabByRelPosition(1);
|
||||
}
|
||||
|
||||
getPreviousTab () {
|
||||
return this.getTabByRelPosition(-1);
|
||||
}
|
||||
|
||||
getTabs () {
|
||||
return this.tabs;
|
||||
}
|
||||
|
@ -231,6 +244,9 @@ class Tab extends EventEmitter {
|
|||
}
|
||||
|
||||
setPosition (newPosition) {
|
||||
if (newPosition === 0) {
|
||||
return null;
|
||||
}
|
||||
let tabContainer = this.tabGroup.tabContainer;
|
||||
let tabs = tabContainer.children;
|
||||
let oldPosition = this.getPosition() - 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue