Underline Tabs
A keyboard-accessible tab strip with the active tab underlined.
6 फ्रेमवर्कमध्यम
An iOS-style segmented control where the selected tab lifts to a card.
<!-- Segmented control: the tinted track is the tablist; aria-selected: paints the raised card. -->
<div class="max-w-2xl" data-tabs-segmented>
<div class="inline-flex max-w-full gap-1 overflow-x-auto rounded-lg bg-gray-100 p-1 dark:bg-gray-800" role="tablist" aria-label="Ticket status">
<button class="whitespace-nowrap rounded-md px-3 py-1.5 text-sm font-medium text-gray-600 transition-colors hover:text-gray-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 motion-reduce:transition-none aria-selected:bg-white aria-selected:text-gray-900 aria-selected:shadow-sm dark:text-gray-400 dark:hover:text-gray-100 dark:focus-visible:ring-blue-400 dark:aria-selected:bg-gray-950 dark:aria-selected:text-gray-100" type="button" role="tab" id="seg-all" aria-controls="seg-panel-all" aria-selected="true" tabindex="0">All</button>
<button class="whitespace-nowrap rounded-md px-3 py-1.5 text-sm font-medium text-gray-600 transition-colors hover:text-gray-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 motion-reduce:transition-none aria-selected:bg-white aria-selected:text-gray-900 aria-selected:shadow-sm dark:text-gray-400 dark:hover:text-gray-100 dark:focus-visible:ring-blue-400 dark:aria-selected:bg-gray-950 dark:aria-selected:text-gray-100" type="button" role="tab" id="seg-open" aria-controls="seg-panel-open" aria-selected="false" tabindex="-1">Open</button>
<button class="whitespace-nowrap rounded-md px-3 py-1.5 text-sm font-medium text-gray-600 transition-colors hover:text-gray-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 motion-reduce:transition-none aria-selected:bg-white aria-selected:text-gray-900 aria-selected:shadow-sm dark:text-gray-400 dark:hover:text-gray-100 dark:focus-visible:ring-blue-400 dark:aria-selected:bg-gray-950 dark:aria-selected:text-gray-100" type="button" role="tab" id="seg-closed" aria-controls="seg-panel-closed" aria-selected="false" tabindex="-1">Closed</button>
</div>
<div class="pt-4 text-sm leading-relaxed text-gray-600 focus-visible:rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 dark:text-gray-300 dark:focus-visible:ring-blue-400" role="tabpanel" id="seg-panel-all" aria-labelledby="seg-all" tabindex="0"><p>Every ticket across the workspace, newest first.</p></div>
<div class="pt-4 text-sm leading-relaxed text-gray-600 focus-visible:rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 dark:text-gray-300 dark:focus-visible:ring-blue-400" role="tabpanel" id="seg-panel-open" aria-labelledby="seg-open" tabindex="0" hidden><p>18 open tickets, 4 waiting on a customer reply.</p></div>
<div class="pt-4 text-sm leading-relaxed text-gray-600 focus-visible:rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 dark:text-gray-300 dark:focus-visible:ring-blue-400" role="tabpanel" id="seg-panel-closed" aria-labelledby="seg-closed" tabindex="0" hidden><p>231 closed this quarter, median resolution 6h.</p></div>
</div>
<script>
(function () {
document.querySelectorAll('[data-tabs-segmented]').forEach(function (root) {
var tabs = [].slice.call(root.querySelectorAll('[role="tab"]'));
function panelFor(t) { return document.getElementById(t.getAttribute('aria-controls')); }
function select(i, focus) {
tabs.forEach(function (t, n) {
var on = n === i;
t.setAttribute('aria-selected', String(on));
t.tabIndex = on ? 0 : -1; // roving tabindex
var p = panelFor(t);
if (p) p.hidden = !on;
});
if (focus) tabs[i].focus();
}
tabs.forEach(function (t, i) {
t.addEventListener('click', function () { select(i, false); });
t.addEventListener('keydown', function (e) {
var n = -1;
if (e.key === 'ArrowRight') n = (i + 1) % tabs.length;
else if (e.key === 'ArrowLeft') n = (i - 1 + tabs.length) % tabs.length;
else if (e.key === 'Home') n = 0;
else if (e.key === 'End') n = tabs.length - 1;
else return;
e.preventDefault();
select(n, true);
});
});
});
})();
</script>| Prop | टाइप | डिफ़ॉल्ट | विवरण |
|---|---|---|---|
itemsआवश्यक | TabItem[] | - | रेंडर की जाने वाली आइटम की सूची। |
defaultTabId | string | - | माउंट पर खुले रहने वाले आइटम की id। |
onSelect | (id: string) => void | - | यूज़र द्वारा चुने गए मेन्यू आइटम के साथ चलता है। |
className | string | - | रूट एलिमेंट पर मर्ज होने वाली अतिरिक्त क्लासेज़। |
The track is the `tablist` and the selected segment is a white, shadowed card inside it; keep the track padding and the segment radius in step or the card will not sit flush. Best for two to four short, equal-weight options - longer labels or more than four segments want the scrollable or overflow variants.