![NOTE] Fork of Electron Tabs by Brrd

Electron Tabs

Electron Tab Demo

Features

Installation

npm install --save electron-tabs

Getting started

Define the following webPreferences options in the main process:

const mainWindow = new electron.BrowserWindow({
  webPreferences: {
    webviewTag: true
  }
});

Then add the following markup where you want the tabs to display:

<tab-group></tab-group>

<script src="node_modules/electron-tabs/dist/electron-tabs.js"></script>

Options

You can add options by setting <tab-group> element attributes:

<tab-group new-tab-button="true" sortable="true"></tab-group>

The following attributes are supported:

Methods

Use TabGroup methods and manipulate tabs in a script after calling electron-tabs.js.

<tab-group new-tab-button="true"></tab-group>

<script src="path/to/electron-tabs.js"></script>

<script>
  // Select tab-group
  const tabGroup = document.querySelector("tab-group");

  // Setup the default tab which is created when the "New Tab" button is clicked
  tabGroup.setDefaultTab({
    title: "New Page",
    src: "path/to/new-page.html",
    active: true
  });

  // Do stuff
  const tab = tabGroup.addTab({
    title: "electron-tabs | SudoVanilla Registry",
    src: "https://npm.sudovanilla.org/-/web/detail/@sudovanilla/electron-tabs"
  });
  const pos = tab.getPosition();
  console.log("Tab position is " + pos);
</script>

TabGroup

tabGroup.addTab(options)

Add a new tab and returns the related Tab instance.

tabGroup.setDefaultTab(options)

Define default options to use for creating the tab when the "New Tab" button is clicked or when calling tabGroup.addTab() with no parameter.

tabGroup.setDefaultTab({
  title: "New Page",
  src: "path/to/new-page.html",
  active: true
});

tabGroup.getTab(id)

Retrieve an instance of Tab from this id (return null if not found).

tabGroup.getTabByPosition(position)

Retrieve an instance of Tab from this position (return null if not found). A negative value is an offset from the right.

To get the tab in the leftmost position:

tabGroup.getTabByPosition(1);

To get the tab in the rightmost position:

tabGroup.getTabByPosition(-1);

tabGroup.getTabByRelPosition(position)

Retrieve an instance of Tab from this position relative to the active tab (return null if not found).

tabGroup.getNextTab() is an alias to tabGroup.getTabByRelPosition(1).

tabGroup.getPreviousTab() is an alias to tabGroup.getTabByRelPosition(-1).

tabGroup.getActiveTab()

Return the active tab (return null if none).

tabGroup.getTabs()

Return all registered tabs.

tabGroup.eachTab(fn, thisArg)

Loop through the list of tabs in tabGroup and execute the fn function for each tab. fn is called with the following parameters:

thisArg (optional) is the value to use as this when executing fn.

Tab

Instances of Tab are returned by the tabGroup.addTab() method.

tab.setTitle(title)

Set tab title.

tab.getTitle()

Get current tab title.

tab.setPosition(newPosition)

Move tab to the specified position. See tabGroup.getTabByPosition for information about positions.

tab.getPosition(fromRight)

Get the tab position. If fromRight is true the index returned is negative and is the offset from the right.

tab.activate()

Activate this tab. The class "active" is added to the active tab.

tab.show(flag)

Toggle the "visible" class on the tab. tab.hide() is an alias to tab.show(false).

tab.hasClass(classname)

Return true if the tab element has the specified classname. Useful for checking if a tab is "active" or "visible".

tab.close(force)

Close the tab (and activate another tab if relevant). When force is set to true the tab will be closed even if it is not closable.

Events

The following events are emitted:

You can also use tab.once to automatically remove the listener when invoked:

Access Electron webview element

You can access the webview element and use its methods with through the Tab.webview attribute. See webview documentation.

let webview = tab.webview;
webview.loadURL("file://path/to/new/page.html");

Custom styles

To customize tab-group styles, set new values to electron-tabs CSS variables in your application stylesheet.

Since TabGroup is a Web Component you won't be able to change its styles directly from your app stylesheet. If you need more control over it then you can add a <style> tag inside the <tab-group > element:

<tab-group new-tab-button="true" sortable="true">
  <style>
    /* Write your own CSS rules here... */
  </style>
</tab-group>

This method is particularly useful when you need to define tab styles:

<tab-group new-tab-button="true" sortable="true">
  <style>
    /* Add custom styles */
    .my-custom-tab {
      color: red;
      font-weight: bold;
    }
  </style>
</tab-group>

<script src="path/to/electron-tabs.js"></script>

<script>
  const tabGroup = document.querySelector("tab-group");

  tabGroup.addTab({
    title: "Tab with custom style",
    src: "page.html",
    ready: function(tab) {
      tab.element.classList.add("my-custom-tab");
    }
  });
</script>

Development

electron-tabs uses TypeScript and Parcel under the hood.

Requirements

Git and Node 12+.

Build

# Clone this repo
git clone git@ark.sudovanilla.org:korbs/electron-tabs.git
cd electron-tabs

# Install dependencies
npm install

# Build
npm run build

# ...or watch
npm run watch

Demo

npm run demo

License

The MIT License (MIT NON-AI License) - Copyright (c) 2022 Thomas Brouard, Copyright (c) 2025 SudoVanilla

@sudovanilla/electron-tabs - Installation

To install @sudovanilla/electron-tabs via this registry, you'll need to install via the --registry parameter with your package manager.

n

NPM

npm install @sudovanilla/electron-tabs --registry https://js.registry.sudovanilla.org

Learn more about the --registry parameter.

Yarn

yarn config set registry https://js.registry.sudovanilla.org
yarn install @sudovanilla/electron-tabs

Learn more about the config option.

PNPM

pnpm install @sudovanilla/electron-tabs --registry https://js.registry.sudovanilla.org

Learn more about the --registry parameter.

Bun Logo

Bun

bun install @sudovanilla/electron-tabs --registry https://js.registry.sudovanilla.org

Learn more about the --registry parameter.

Learn more about setting this up in your bunfig.toml configuration.


For Deno, add the following to your .npmrc file in your directory:

registry="https://js.registry.sudovanilla.org"

Then run the deno install command.

@sudovanilla/electron-tabs - Download

Download Tarball (v1.3.1)

Integrity sha512-a4XynqwCYEMHJRikqPU30l0wEW1Z28kQ6HOG1csPpJeUko1kLcKX+MlFiNgTwDFmUhcxyoVRa4GRhXr/9jcVbQ==
SHASUM 3cac822eb8b9ca2b7267ab7bf03146e945cc2d7f
Tarball https://js.registry.sudovanilla.org/@sudovanilla/electron-tabs/-/electron-tabs-1.3.1.tgz