chrome-tabs
repository·gh-pages·Indexed 23 days ago
https://github.com/adamschwartz/chrome-tabsA web-based UI component (version 5.4.0) that replicates Google Chrome's tab bar using HTML, CSS, and JS. It features drag-and-drop functionality powered by Draggabilly and provides an API for managing tabs via methods like addTab(), removeTab(), updateTab(), and setCurrentTab(), as well as events for tab addition, removal, reordering, and active tab changes.
What's inside chrome-tabs
- Chrome Tabs in Chrome is a project that provides a visual interface mimicking Chrome's tab behavior within a web environment. It features drag-and-drop support for tab manipulation, powered by the Draggabilly library.
Listen to ChromeTabs events
gh-pagesThe
ChromeTabsinstance emits custom events on the container element (this.el). You can listen for these events to react to UI changes.Emitted Events:
tabAdd: Fired when a tab is added. Detail contains{ tabEl }.tabRemove: Fired when a tab is removed. Detail contains{ tabEl }.activeTabChange: Fired when the active tab changes. Detail contains{ tabEl }.tabReorder: Fired when a tab is dragged to a new position. Detail contains{ tabEl, originIndex, destinationIndex }.
Manage active tabs
gh-pagesYou can programmatically control which tab is currently active using
setCurrentTab(tabEl).activeTabEl: A getter that returns the currently active tab element (the one with theactiveattribute) ornullif none are active.hasActiveTab(): A method that returnstrueif there is an active tab,falseotherwise.setCurrentTab(tabEl): Sets the provided element as the active tab and emits theactiveTabChangeevent.
Initialize ChromeTabs
gh-pagesTo useChromeTabs, instantiate theChromeTabsclass and call theinit(el)method, passing the DOM element that will serve as the container for the tabs. Theinitmethod sets up styles, event listeners (including window resize), and the drag-and-drop functionality usingDraggabilly.Remove a tab with removeTab()
gh-pagesCallremoveTab(tabEl)to remove a specific tab element from the UI. If the removed tab was the active tab,ChromeTabswill automatically attempt to set the next or previous tab as the active one. ThetabRemoveevent is emitted on the container element.Update an existing tab with updateTab()
gh-pagesUseupdateTab(tabEl, tabProperties)to modify the content of an existing tab element. This allows you to change thetitle,favicon, orid(viadata-tab-id).Add a new tab with addTab()
gh-pagesUse
addTab(tabProperties, options)to create a new tab.tabProperties:
title(string): The text to display in the tab. Defaults to'New tab'.favicon(string|boolean): A URL to a favicon image. Iffalse, the favicon element is hidden.id(string): An optional ID to be set as adata-tab-idattribute on the tab element.
options:
animate(boolean): Whether to trigger a CSS animation when the tab is added. Defaults totrue.background(boolean): Iftrue, the new tab will not be set as the active tab. Defaults tofalse.
When a tab is added, the
tabAddevent is emitted on the container element.