Skip to content

Commit e42bcf9

Browse files
committed
Implement scrolling to active tab, fix styles, add release guard
1 parent 0b65894 commit e42bcf9

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

packages/widgets/src/tabbar.ts

+33-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ export class TabBar<T> extends Widget {
370370
if (value) {
371371
this.node.classList.add('lm-mod-scrollable');
372372
} else {
373-
this.node.classList.add('lm-mod-scrollable');
373+
this.node.classList.remove('lm-mod-scrollable');
374374
}
375375
this.maybeSwitchScrollButtons();
376376
}
@@ -708,14 +708,41 @@ export class TabBar<T> extends Widget {
708708
content[i] = renderer.renderTab({ title, current, zIndex });
709709
}
710710
VirtualDOM.render(content, this.contentNode);
711+
711712
this.maybeSwitchScrollButtons();
713+
714+
// Scroll the current tab into view.
715+
this.scrollCurrentIntoView();
712716
}
713717

714718
protected onResize(msg: Widget.ResizeMessage): void {
715719
super.onResize(msg);
716720
this.maybeSwitchScrollButtons();
717721
}
718722

723+
/**
724+
* Scroll the current tab into view.
725+
*/
726+
protected scrollCurrentIntoView() {
727+
if (this.scrollingEnabled) {
728+
const contentNode = this.contentNode;
729+
const currentNode = contentNode.children.item(this.currentIndex);
730+
if (currentNode) {
731+
currentNode.scrollIntoView();
732+
if (this.orientation == 'horizontal') {
733+
contentNode.scrollTop = 0;
734+
} else {
735+
contentNode.scrollLeft = 0;
736+
}
737+
} else {
738+
console.error('Current tab node not found');
739+
}
740+
}
741+
}
742+
743+
/**
744+
* Show/hide scroll buttons if needed.
745+
*/
719746
protected maybeSwitchScrollButtons() {
720747
const scrollBefore = this.scrollBeforeButtonNode;
721748
const scrollAfter = this.scrollAfterButtonNode;
@@ -1174,6 +1201,11 @@ export class TabBar<T> extends Widget {
11741201
return;
11751202
}
11761203

1204+
// Do nothing if neither press nor release was on a tab.
1205+
if (index === -1 && data.index === -1) {
1206+
return;
1207+
}
1208+
11771209
// Ignore the release if the title is not closable.
11781210
let title = this._titles[index];
11791211
if (!title.closable) {

packages/widgets/style/tabbar.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
display: none !important;
9595
}
9696

97-
.lm-TabBar-addButton.lm-mod-hidden {
97+
.lm-TabBar-button.lm-mod-hidden {
9898
display: none !important;
9999
}
100100

0 commit comments

Comments
 (0)