Tabs - Reorderable Tabs
Reorderable Tabs
Options
Styles
--cj-tab-background#DEECFD--cj-tab-color#416DA3--cj-tab-border-color#8DB3E3--cj-tab-hover-background#E8F2FF--cj-tab-selected-background#DEECFD--cj-tab-selected-color#15498B/* Choose a color to generate CSS overrides. */_tabs.scssscss
.cj-tabs {
min-width: 0;
max-width: 100%;
font:
12px tahoma,
arial,
verdana,
sans-serif;
color: #000;
}
.cj-tabs__bar {
position: relative;
box-sizing: border-box;
display: flex;
min-width: 0;
max-width: 100%;
--cj-tab-bar-height: 27px;
}
.cj-tabs--top > .cj-tabs__bar,
.cj-tabs--bottom > .cj-tabs__bar {
height: var(--cj-tab-bar-height);
border: solid #99bce8;
border-width: 1px 1px 0;
background: #cbdbef linear-gradient(#dde8f5, #cbdbef);
}
.cj-tabs--top > .cj-tabs__bar::after,
.cj-tabs--bottom > .cj-tabs__bar::after {
content: "";
position: absolute;
z-index: 1;
inset: auto 0 0;
box-sizing: border-box;
height: 3px;
border-top: 1px solid #99bce8;
background: #deecfd;
pointer-events: none;
}
.cj-tabs__list {
flex: 1 1 0;
box-sizing: border-box;
min-width: 0;
max-width: 100%;
display: flex;
align-items: flex-start;
gap: 2px;
padding: 1px 2px 2px;
overflow-x: auto;
overflow-y: hidden;
scrollbar-width: none;
}
.cj-tabs__list::-webkit-scrollbar {
display: none;
}
.cj-tabs__tab {
--cj-tab-gradient: to bottom;
appearance: none;
box-sizing: border-box;
flex: none;
position: relative;
inline-size: 100%;
min-height: 23px;
height: 23px;
margin: 0;
padding: 3px 9px;
border: solid var(--cj-tab-border-color, #8db3e3);
border-width: 1px 1px 0;
border-radius: 4px 4px 0 0;
background: var(
--cj-tab-background,
#deecfd
linear-gradient(var(--cj-tab-gradient), #ccdef6, #d6e6fa 25%, #deecfd 45%)
);
box-shadow:
inset 0 1px #fff,
inset -1px 0 #fff,
inset 1px 0 #fff;
color: var(--cj-tab-color, #416da3);
font:
bold 11px/13px tahoma,
arial,
verdana,
sans-serif;
white-space: nowrap;
cursor: pointer;
}
.cj-tabs__label {
display: inline-block;
transform: translateX(-0.25px);
}
.cj-tabs__tab:hover:not(:disabled):not([aria-selected="true"]) {
border-color: var(--cj-tab-border-color, #8db3e3);
background: var(
--cj-tab-hover-background,
#e8f2ff
linear-gradient(var(--cj-tab-gradient), #d7e5fd, #e0edff 25%, #e8f2ff 45%)
);
color: #416da3;
}
.cj-tabs__tab[aria-selected="true"] {
z-index: 2;
border-color: var(--cj-tab-border-color, #8db3e3);
background: var(
--cj-tab-selected-background,
#deecfd
linear-gradient(var(--cj-tab-gradient), #fff, #f5f9fe 25%, #deecfd 45%)
);
color: var(--cj-tab-selected-color, #15498b);
}
.cj-tabs__tab:disabled {
border-color: #bbd2ef;
background: #e1ecfa linear-gradient(var(--cj-tab-gradient), #e1ecfa, #ecf4fe);
color: #c3b3b3;
opacity: 1;
cursor: default;
}
.cj-tabs__tab:focus {
outline: none;
}
.cj-tabs__tab:focus::after {
content: "";
position: absolute;
inset: 3px 9px;
outline: 1px dotted #416da3;
pointer-events: none;
}
.cj-tabs__panel {
position: relative;
box-sizing: border-box;
min-width: 0;
overflow-wrap: anywhere;
border: 1px solid #99bce8;
padding: 12px;
background: #fff;
color: #000;
font:
12px/1.5 tahoma,
arial,
verdana,
sans-serif;
}
.cj-loading-mask {
box-sizing: border-box;
position: absolute;
z-index: var(--cj-z-component-mask, 10);
inset: 0;
display: grid;
place-items: center;
background: rgba(204, 204, 204, 0.5);
border: 1px solid transparent;
}
.cj-loading-mask__message {
position: absolute;
top: 50%;
left: 50%;
width: max-content;
height: max-content;
padding: 2px;
border: 1px solid #99bce8;
background: #dfe9f6;
translate: round(nearest, -50%, 1px) round(down, -50%, 1px);
}
.cj-loading-mask__inner {
padding: 0 5px;
border: 1px solid #a3bad9;
background: #eee;
color: #222;
font: normal 11px var(--cj-font);
}
.cj-loading-mask__content {
position: relative;
padding: 5px 5px 5px 20px;
}
.cj-loading-mask__spinner {
position: absolute;
left: 0;
top: 50%;
width: 16px;
height: 16px;
background: url("./loading-mask.svg") center / 16px 16px no-repeat;
translate: 0 -50%;
animation: cj-spin 0.8s linear infinite;
}
@keyframes cj-spin {
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: reduce) {
.cj-loading-mask__spinner {
animation: none;
}
}
.cj-tabs__panel[hidden] {
display: none;
}
.cj-tabs__item {
position: relative;
display: flex;
flex: none;
width: calc-size(max-content, round(up, size, 1px));
}
.cj-tabs__list[data-cj-reorderable] .cj-tabs__item[draggable="true"] {
cursor: grab;
}
.cj-tabs__item:has(.cj-tabs__close) .cj-tabs__tab {
padding-right: 23px;
}
.cj-tabs__item:has(.cj-tabs__close) .cj-tabs__tab:focus::after {
right: 23px;
}
.cj-tabs__close {
position: absolute;
z-index: 2;
right: 3.5px;
top: 3px;
width: 11px;
height: 11px;
padding: 0;
border: 0;
background: url("./tab-close-glyph.svg") 0 0 / 33px 11px no-repeat;
opacity: 0.6;
cursor: pointer;
}
.cj-tabs__close:hover {
opacity: 1;
}
.cj-tabs__close:disabled {
opacity: 0.3;
}
.cj-tabs__close:focus-visible {
outline: 2px solid #3978b5;
}
.cj-tabs__icon {
display: inline-block;
margin-right: 5px;
color: inherit;
}
.cj-tabs__tab--icon-only .cj-tabs__icon {
margin-right: 0;
}
.cj-tabs__icon .cj-icon {
width: 16px;
height: 16px;
}
.cj-tabs__panels {
min-width: 0;
flex: 1;
}
.cj-tabs__panels > .cj-tabs__panel {
height: 100%;
min-height: 110px;
}
.cj-tabs--bottom {
display: flex;
flex-direction: column;
}
.cj-tabs--bottom > .cj-tabs__bar {
--cj-tab-bar-height: 28px;
order: 2;
border-width: 0 1px 1px;
background: #cbdbef linear-gradient(to top, #dde8f5, #cbdbef);
}
.cj-tabs--bottom > .cj-tabs__bar::after {
inset: 0 0 auto;
border-width: 0 0 1px;
border-bottom-style: solid;
border-color: #99bce8;
}
.cj-tabs--bottom > .cj-tabs__bar > .cj-tabs__list {
align-items: flex-end;
padding: 2px 2px 1px;
}
.cj-tabs--bottom > .cj-tabs__bar > .cj-tabs__list .cj-tabs__tab {
--cj-tab-gradient: to top;
height: 24px;
padding-top: 4px;
border-width: 0 1px 1px;
border-radius: 0 0 4px 4px;
box-shadow:
inset 0 -1px #fff,
inset -1px 0 #fff,
inset 1px 0 #fff;
}
.cj-tabs--bottom > .cj-tabs__bar .cj-tabs__close {
top: 2px;
}
.cj-tabs--left,
.cj-tabs--right {
display: flex;
}
:is(.cj-tabs--left, .cj-tabs--right) > .cj-tabs__bar {
border: solid #99bce8;
border-width: 1px 0 1px 1px;
background: #cbdbef linear-gradient(to right, #dde8f5, #cbdbef);
}
:is(.cj-tabs--left, .cj-tabs--right) > .cj-tabs__bar::after {
content: "";
position: absolute;
z-index: 1;
inset: 0 0 0 auto;
box-sizing: border-box;
width: 3px;
border-left: 1px solid #99bce8;
background: #deecfd;
pointer-events: none;
}
:is(.cj-tabs--left, .cj-tabs--right) > .cj-tabs__bar > .cj-tabs__list {
min-height: 0;
flex-direction: column;
padding: 1px 2px 2px 1px;
margin-bottom: 1px;
overflow-y: auto;
overflow-x: hidden;
}
.cj-tabs--left > .cj-tabs__bar > .cj-tabs__list {
margin-left: 1px;
padding-left: 0;
}
:is(.cj-tabs--left, .cj-tabs--right) .cj-tabs__item {
width: auto;
height: calc-size(max-content, round(up, size, 1px));
}
:is(.cj-tabs--left, .cj-tabs--right) .cj-tabs__tab {
--cj-tab-gradient: to left;
writing-mode: vertical-rl;
align-self: flex-start;
height: auto;
min-height: 0;
width: 23px;
padding: 9px 4px 9px 3px;
border-width: 1px 1px 1px 0;
border-radius: 0 4px 4px 0;
box-shadow:
inset -1px 0 #fff,
inset 0 -1px #fff,
inset 0 1px #fff;
}
.cj-tabs--left .cj-tabs__tab {
transform: translateX(-0.5px) rotate(180deg);
}
.cj-tabs--right > .cj-tabs__bar {
order: 2;
border-width: 1px 1px 1px 0;
background: #cbdbef linear-gradient(to left, #dde8f5, #cbdbef);
}
.cj-tabs--right > .cj-tabs__bar::after {
inset: 0 auto 0 0;
border-left: 0;
border-right: 1px solid #99bce8;
}
.cj-tabs--right > .cj-tabs__bar > .cj-tabs__list {
padding-inline: 2px 1px;
}
:is(.cj-tabs--left, .cj-tabs--right)
.cj-tabs__item:has(.cj-tabs__close)
.cj-tabs__tab {
padding-right: 4px;
padding-bottom: 23px;
}
:is(.cj-tabs--left, .cj-tabs--right) .cj-tabs__tab:focus::after {
inset: 9px 3px;
}
:is(.cj-tabs--left, .cj-tabs--right)
.cj-tabs__item:has(.cj-tabs__close)
.cj-tabs__tab:focus::after {
bottom: 23px;
}
.cj-tabs--left .cj-tabs__close {
top: 2px;
left: 2px;
width: 12px;
height: 12px;
background: url("./tab-close-left.svg") 0 0 / 12px 12px no-repeat;
}
.cj-tabs--right .cj-tabs__close {
top: auto;
right: 3px;
bottom: 3.5px;
background-position-x: -22px;
}
:is(.cj-tabs--left, .cj-tabs--right) .cj-tabs__icon {
margin-right: 0;
margin-bottom: 4px;
}
.cj-tabs--left .cj-tabs__icon {
transform: rotate(180deg);
}
:is(.cj-tabs--left, .cj-tabs--right) .cj-tabs__tab--icon-only .cj-tabs__icon {
margin-bottom: 0;
}
.cj-tabs--plain:is(.cj-tabs--top, .cj-tabs--bottom) > .cj-tabs__bar {
border-color: transparent;
border-inline-width: 0;
background: none;
}
.cj-tabs--plain:is(.cj-tabs--left, .cj-tabs--right) > .cj-tabs__bar {
border-color: transparent;
border-block-width: 0;
background: none;
}
.cj-tabs--framed {
padding: 5px;
border: 1px solid #99bce8;
border-radius: 4px;
background: #dfeaf8;
}
.cj-tabs--left > .cj-tabs__bar,
.cj-tabs--right > .cj-tabs__bar {
flex: 0 0 27px;
flex-direction: column;
min-height: 0;
contain: size;
}
.cj-tabs--left:has(> .cj-tabs__footer:not([hidden])),
.cj-tabs--right:has(> .cj-tabs__footer:not([hidden])) {
flex-wrap: wrap;
}
.cj-tabs--left > .cj-tabs__footer,
.cj-tabs--right > .cj-tabs__footer {
flex-basis: 100%;
order: 3;
}
.cj-tabs--bottom > .cj-tabs__footer {
order: 3;
}
.cj-tabs__footer {
box-sizing: border-box;
padding: 3px 4px;
border: 1px solid #99bce8;
border-top: 0;
background: linear-gradient(#f1f6fd, #d6e5f6);
}
.cj-tabs__footer[hidden],
.cj-tabs__scroll[hidden] {
display: none;
}
.cj-tabs__add-icon {
display: inline-block;
width: 13px;
height: 13px;
background: url("./tab-add.svg") center / 13px 13px no-repeat;
}
.cj-tabs__scroll {
--cj-scroll-x: -18px;
--cj-scroll-y: 0px;
--cj-scroll-hover-x: 18px;
--cj-scroll-hover-y: 0px;
appearance: none;
box-sizing: border-box;
flex: 0 0 18px;
width: 18px;
min-height: 0;
padding: 0;
border: 0;
background: url("./tab-scroll-glyph.svg") no-repeat;
background-position: var(--cj-scroll-x) var(--cj-scroll-y);
cursor: pointer;
}
.cj-tabs__scroll--next {
--cj-scroll-x: -42px;
--cj-scroll-hover-x: -18px;
}
.cj-tabs__scroll:hover:not(:disabled) {
background-position: calc(var(--cj-scroll-x) + var(--cj-scroll-hover-x))
calc(var(--cj-scroll-y) + var(--cj-scroll-hover-y));
}
.cj-tabs__scroll:disabled {
opacity: 0.5;
cursor: default;
}
.cj-tabs__scroll:focus-visible {
outline: 1px dotted #333;
outline-offset: -3px;
}
.cj-tabs--bottom .cj-tabs__scroll {
--cj-scroll-y: -57px;
}
:is(.cj-tabs--left, .cj-tabs--right) .cj-tabs__scroll {
--cj-scroll-x: 0px;
--cj-scroll-y: -102px;
--cj-scroll-hover-x: 0px;
--cj-scroll-hover-y: 18px;
width: auto;
}
.cj-tabs--left .cj-tabs__scroll--next {
--cj-scroll-x: -42px;
--cj-scroll-y: -84px;
--cj-scroll-hover-y: -18px;
}
.cj-tabs--right .cj-tabs__scroll {
--cj-scroll-x: -16px;
--cj-scroll-y: -144px;
}
.cj-tabs--right .cj-tabs__scroll--next {
--cj-scroll-x: -58px;
--cj-scroll-y: -126px;
--cj-scroll-hover-y: -18px;
}
.cj-tabs__item--drop-before::before,
.cj-tabs__item--drop-after::after {
content: "";
position: absolute;
z-index: 4;
top: 0;
bottom: 0;
width: 2px;
background: #356ba0;
pointer-events: none;
}
.cj-tabs__item--drop-before::before {
left: -2px;
}
.cj-tabs__item--drop-after::after {
right: -2px;
}
.cj-tabs--left .cj-tabs__item--drop-before::before,
.cj-tabs--right .cj-tabs__item--drop-before::before,
.cj-tabs--left .cj-tabs__item--drop-after::after,
.cj-tabs--right .cj-tabs__item--drop-after::after {
left: 0;
right: 0;
width: auto;
height: 2px;
}
.cj-tabs--left .cj-tabs__item--drop-before::before,
.cj-tabs--right .cj-tabs__item--drop-before::before {
top: -2px;
bottom: auto;
}
.cj-tabs--left .cj-tabs__item--drop-after::after,
.cj-tabs--right .cj-tabs__item--drop-after::after {
top: auto;
bottom: -2px;
}Reorder tabs by dragging or using Alt+Shift and the arrow keys.
The tabs in this example are reorderable. Drag any tab to change the order.
This panel contains enough content to demonstrate scrolling while the tab bar stays in place.
Drag a tab by its label to change its position. The selected panel remains connected to its tab.
The fixed tab cannot be dragged, but other tabs can still be placed on either side of it.
Use the close control on a tab to remove it. When the active tab closes, another available tab is selected.
The button below this panel adds a new tab and opens it. Add several tabs to reveal the scrolling controls.
When the tab bar runs out of space, use its arrows to move through the hidden tabs.
Keyboard users can switch tabs with the arrow keys and reorder them with Alt, Shift and an arrow key.
Each tab keeps its own panel, so switching between tabs does not replace the surrounding page.
The active tab is brought into view automatically when you navigate to it with the keyboard.
You can close the tabs you no longer need and add another whenever you want to continue exploring.
This panel contains enough content to demonstrate scrolling while the tab bar stays in place.
Drag a tab by its label to change its position. The selected panel remains connected to its tab.
The fixed tab cannot be dragged, but other tabs can still be placed on either side of it.
Use the close control on a tab to remove it. When the active tab closes, another available tab is selected.
The button below this panel adds a new tab and opens it. Add several tabs to reveal the scrolling controls.
When the tab bar runs out of space, use its arrows to move through the hidden tabs.
Keyboard users can switch tabs with the arrow keys and reorder them with Alt, Shift and an arrow key.
Each tab keeps its own panel, so switching between tabs does not replace the surrounding page.
The active tab is brought into view automatically when you navigate to it with the keyboard.
You can close the tabs you no longer need and add another whenever you want to continue exploring.
This tab cannot be moved.
This panel contains enough content to demonstrate scrolling while the tab bar stays in place.
Drag a tab by its label to change its position. The selected panel remains connected to its tab.
The fixed tab cannot be dragged, but other tabs can still be placed on either side of it.
Use the close control on a tab to remove it. When the active tab closes, another available tab is selected.
The button below this panel adds a new tab and opens it. Add several tabs to reveal the scrolling controls.
When the tab bar runs out of space, use its arrows to move through the hidden tabs.
Keyboard users can switch tabs with the arrow keys and reorder them with Alt, Shift and an arrow key.
Each tab keeps its own panel, so switching between tabs does not replace the surrounding page.
The active tab is brought into view automatically when you navigate to it with the keyboard.
You can close the tabs you no longer need and add another whenever you want to continue exploring.
Code
---
import { Tabs, Tab, TabPanel } from 'classijs';
import 'classijs/styles.css';
---
<Tabs id="demo-tabs" label="Example sections" reorderable addable>
<Fragment slot="tabs">
<Tab id="demo-tab-0" selected closable closeLabel="Close Tab 1">Tab 1</Tab>
<Tab id="demo-tab-1" closable closeLabel="Close Tab 2">Tab 2</Tab>
<Tab id="demo-tab-2" closable closeLabel="Close Tab 3">Tab 3</Tab>
<Tab id="demo-tab-3" closable closeLabel="Close Non Reorderable" reorderable={false}>Non Reorderable</Tab>
<Tab id="demo-tab-4" closable closeLabel="Close Tab 4">Tab 4</Tab>
</Fragment>
<TabPanel for="demo-tab-0" selected>The tabs in this example are reorderable. Drag any tab to change the order.</TabPanel>
<TabPanel for="demo-tab-1">This panel contains enough content to demonstrate scrolling while the tab bar stays in place.
Drag a tab by its label to change its position. The selected panel remains connected to its tab.
The fixed tab cannot be dragged, but other tabs can still be placed on either side of it.
Use the close control on a tab to remove it. When the active tab closes, another available tab is selected.
The button below this panel adds a new tab and opens it. Add several tabs to reveal the scrolling controls.
When the tab bar runs out of space, use its arrows to move through the hidden tabs.
Keyboard users can switch tabs with the arrow keys and reorder them with Alt, Shift and an arrow key.
Each tab keeps its own panel, so switching between tabs does not replace the surrounding page.
The active tab is brought into view automatically when you navigate to it with the keyboard.
You can close the tabs you no longer need and add another whenever you want to continue exploring.</TabPanel>
<TabPanel for="demo-tab-2">This panel contains enough content to demonstrate scrolling while the tab bar stays in place.
Drag a tab by its label to change its position. The selected panel remains connected to its tab.
The fixed tab cannot be dragged, but other tabs can still be placed on either side of it.
Use the close control on a tab to remove it. When the active tab closes, another available tab is selected.
The button below this panel adds a new tab and opens it. Add several tabs to reveal the scrolling controls.
When the tab bar runs out of space, use its arrows to move through the hidden tabs.
Keyboard users can switch tabs with the arrow keys and reorder them with Alt, Shift and an arrow key.
Each tab keeps its own panel, so switching between tabs does not replace the surrounding page.
The active tab is brought into view automatically when you navigate to it with the keyboard.
You can close the tabs you no longer need and add another whenever you want to continue exploring.</TabPanel>
<TabPanel for="demo-tab-3">This tab cannot be moved.</TabPanel>
<TabPanel for="demo-tab-4">This panel contains enough content to demonstrate scrolling while the tab bar stays in place.
Drag a tab by its label to change its position. The selected panel remains connected to its tab.
The fixed tab cannot be dragged, but other tabs can still be placed on either side of it.
Use the close control on a tab to remove it. When the active tab closes, another available tab is selected.
The button below this panel adds a new tab and opens it. Add several tabs to reveal the scrolling controls.
When the tab bar runs out of space, use its arrows to move through the hidden tabs.
Keyboard users can switch tabs with the arrow keys and reorder them with Alt, Shift and an arrow key.
Each tab keeps its own panel, so switching between tabs does not replace the surrounding page.
The active tab is brought into view automatically when you navigate to it with the keyboard.
You can close the tabs you no longer need and add another whenever you want to continue exploring.</TabPanel>
</Tabs>