Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disableCustomScrollbars option #885

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Tabs } from '../../../../dockview/components/titlebar/tabs';
import { fromPartial } from '@total-typescript/shoehorn';
import { DockviewGroupPanel } from '../../../../dockview/dockviewGroupPanel';
import { DockviewComponent } from '../../../../dockview/dockviewComponent';

describe('tabs', () => {
describe('disableCustomScrollbars', () => {
test('enabled by default', () => {
const cut = new Tabs(
fromPartial<DockviewGroupPanel>({}),
fromPartial<DockviewComponent>({
options: {},
}),
{
showTabsOverflowControl: true,
}
);

expect(
cut.element.querySelectorAll(
'.dv-scrollable > .dv-tabs-container'
).length
).toBe(1);
});

test('enabled when disabled flag is false', () => {
const cut = new Tabs(
fromPartial<DockviewGroupPanel>({}),
fromPartial<DockviewComponent>({
options: {
scrollbars: 'custom',
},
}),
{
showTabsOverflowControl: true,
}
);

expect(
cut.element.querySelectorAll(
'.dv-scrollable > .dv-tabs-container'
).length
).toBe(1);
});

test('disabled when disabled flag is true', () => {
const cut = new Tabs(
fromPartial<DockviewGroupPanel>({}),
fromPartial<DockviewComponent>({
options: {
scrollbars: 'native',
},
}),
{
showTabsOverflowControl: true,
}
);

expect(
cut.element.querySelectorAll(
'.dv-scrollable > .dv-tabs-container'
).length
).toBe(0);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.dv-tabs-container {
display: flex;
height: 100%;
overflow: hidden;
overflow: auto;
scrollbar-width: thin; // firefox

&.dv-horizontal {
Expand Down Expand Up @@ -35,6 +35,12 @@
}
}

.dv-scrollable {
> .dv-tabs-container {
overflow: hidden;
}
}

.dv-tab {
-webkit-user-drag: element;
outline: none;
Expand Down
10 changes: 7 additions & 3 deletions packages/dockview-core/src/dockview/components/titlebar/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,17 @@ export class Tabs extends CompositeDisposable {

this.showTabsOverflowControl = options.showTabsOverflowControl;

const scrollbar = new Scrollbar(this._tabsList);
this._element = scrollbar.element;
if (accessor.options.scrollbars === 'native') {
this._element = this._tabsList;
} else {
const scrollbar = new Scrollbar(this._tabsList);
this._element = scrollbar.element;
this.addDisposables(scrollbar);
}

this.addDisposables(
this._onOverflowTabsChange,
this._observerDisposable,
scrollbar,
this._onWillShowOverlay,
this._onDrop,
this._onTabDragStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
font-size: var(--dv-tabs-and-actions-container-font-size);

&.dv-single-tab.dv-full-width-single-tab {
.dv-scrollable {
flex-grow: 1;
}

.dv-tabs-container {
flex-grow: 1;

Expand Down
8 changes: 8 additions & 0 deletions packages/dockview-core/src/dockview/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ export interface DockviewOptions {
noPanelsOverlay?: 'emptyGroup' | 'watermark';
theme?: DockviewTheme;
disableTabsOverflowList?: boolean;
/**
* Select `native` to use built-in scrollbar behaviours and `custom` to use an internal implementation
* that allows for improved scrollbar overlay UX.
*
* This is only applied to the tab header section. Defaults to `custom`.
*/
scrollbars?: 'native' | 'custom';
}

export interface DockviewDndOverlayEvent extends IAcceptableEvent {
Expand Down Expand Up @@ -116,6 +123,7 @@ export const PROPERTY_KEYS_DOCKVIEW: (keyof DockviewOptions)[] = (() => {
dndEdges: undefined,
theme: undefined,
disableTabsOverflowList: undefined,
scrollbars: undefined,
};

return Object.keys(properties) as (keyof DockviewOptions)[];
Expand Down
1 change: 0 additions & 1 deletion packages/dockview-core/src/scrollbar.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.dv-scrollable {
position: relative;
overflow: hidden;
width: 100%;

.dv-scrollbar-horizontal {
position: absolute;
Expand Down
Loading