Skip to content
Bladewell

<x-widget.tabs>

Tabs Blade component for Laravel and Livewire

Tabs that switch between panels on the page: underlined, underlined and tinted, pills, a segmented track, or stacked beside the panel. Icons and counts on tabs, disabled ones, links as tabs for page navigation, sideways scrolling when there are too many, and remember to keep the open tab in the URL. The arrow keys move between them. Works inside Livewire components, with wire:model for the open tab.

php artisan bladewell:add tabs
Also adds
Icon
Works with
Laravel 12 and 13, Livewire 3 and 4, Tailwind CSS 4.1+, PHP 8.3+

Usage

In scripts

window.tabs is available once the tabs script has loaded. <x-widget.tabs id="settings" …> with a tab key="security"

JavaScript
tabs.open('settings', 'security');

// Or any element of the tabs.
tabs.open(document.querySelector('[data-tabs="settings"]'), 'security');

Livewire

Inside a Livewire component the open tab stays as the person left it through every render, and the panels' content updates. Bind it with wire:model to a property to know it in PHP, or to open one from PHP: public string $tab = 'profile'. Bound, the property decides which tab is open after each render.

Blade
<x-widget.tabs id="account" label="Account" wire:model.live="tab" :tabs="['profile' => 'Profile', 'security' => 'Security']">
    <x-slot:profile>
        <livewire:profile-form />
    </x-slot:profile>
    <x-slot:security>
        @if ($tab === 'security')
            {{-- Only load what the open tab needs. --}}
            <livewire:sessions-list />
        @endif
    </x-slot:security>
</x-widget.tabs>

Examples

Underline

The default: text tabs on a rule. Each tab's panel is the named slot of its key. The arrow keys move between tabs, Home and End jump to the ends, and only the open tab is in the Tab order.

Your name, photo and the email we write to.
Show code
Blade
<x-widget.tabs id="account" label="Account" :tabs="['profile' => 'Profile', 'security' => 'Security', 'notifications' => 'Notifications']">
    <x-slot:profile>Your name, photo and the email we write to.</x-slot:profile>
    <x-slot:security>Password, two-factor authentication and signed-in devices.</x-slot:security>
    <x-slot:notifications>What we email you about, and how often.</x-slot:notifications>
</x-widget.tabs>

Pills

variant="pills": rounded buttons, the open one filled. Good for filters above a list. value opens one other than the first.

Orders waiting to ship.
Show code
Blade
<x-widget.tabs id="order-status" label="Orders" variant="pills" value="open" :tabs="['all' => 'All', 'open' => 'Open', 'shipped' => 'Shipped', 'returned' => 'Returned']">
    <x-slot:all>Every order.</x-slot:all>
    <x-slot:open>Orders waiting to ship.</x-slot:open>
    <x-slot:shipped>Orders on their way.</x-slot:shipped>
    <x-slot:returned>Orders sent back.</x-slot:returned>
</x-widget.tabs>

Segmented

variant="segmented": one track with the open tab raised in it, for two to four short choices.

$12 a month

Show code
Blade
<x-widget.tabs id="billing" label="Billing period" variant="segmented" :tabs="['monthly' => 'Monthly', 'yearly' => 'Yearly']">
    <x-slot:monthly><p class="text-2xl font-semibold">$12 <span class="text-foreground/70 text-sm font-normal">a month</span></p></x-slot:monthly>
    <x-slot:yearly><p class="text-2xl font-semibold">$120 <span class="text-foreground/70 text-sm font-normal">a year, two months free</span></p></x-slot:yearly>
</x-widget.tabs>

Vertical

variant="vertical": tabs stacked beside the panel, for settings pages. The arrow keys go up and down.

Workspace name, language and time zone.
Show code
Blade
<x-widget.tabs id="settings" label="Settings" variant="vertical" :tabs="['general' => 'General', 'team' => 'Team', 'billing' => 'Billing', 'api' => 'API keys']">
    <x-slot:general>Workspace name, language and time zone.</x-slot:general>
    <x-slot:team>Who's in the workspace, and what they can do.</x-slot:team>
    <x-slot:billing>Plan, invoices and payment method.</x-slot:billing>
    <x-slot name="api">Keys for the API, and when each was last used.</x-slot>
</x-widget.tabs>

Icons and badges

A tab can be an array: an icon before its label, a badge after it (a count), or disabled, which the arrow keys skip. variant="tinted" underlines the open tab and puts it on a light wash of the primary colour, like the vertical tabs.

12 unread messages.
Show code
Blade
<x-widget.tabs id="mailbox" label="Mailbox" variant="tinted" :tabs="[
    'inbox' => ['label' => 'Inbox', 'icon' => 'inbox', 'badge' => 12],
    'drafts' => ['label' => 'Drafts', 'icon' => 'pencil', 'badge' => 2],
    'archive' => ['label' => 'Archive', 'icon' => 'file'],
    'spam' => ['label' => 'Spam', 'icon' => 'triangle-alert', 'disabled' => true],
]">
    <x-slot:inbox>12 unread messages.</x-slot:inbox>
    <x-slot:drafts>2 drafts.</x-slot:drafts>
    <x-slot:archive>Everything you've filed away.</x-slot:archive>
    <x-slot:spam>Nothing here.</x-slot:spam>
</x-widget.tabs>

Remember

remember keeps the open tab in the URL (#plans=team), so sharing the link, reloading or going Back opens it again. Several sets on one page share the hash.

For one person: unlimited projects.
Show code
Blade
<x-widget.tabs id="plans" label="Plans" variant="pills" remember :tabs="['personal' => 'Personal', 'team' => 'Team', 'enterprise' => 'Enterprise']">
    <x-slot:personal>For one person: unlimited projects.</x-slot:personal>
    <x-slot:team>For up to 50 people: shared projects and roles.</x-slot:team>
    <x-slot:enterprise>For larger companies: SSO, audit log and support.</x-slot:enterprise>
</x-widget.tabs>

Many tabs

More tabs than fit scroll sideways rather than wrapping, and the open one is scrolled into view as it changes.

Reports for October.
Show code
Blade
<x-widget.tabs id="months" label="Month" value="october" class="max-w-md" :tabs="[
    'january' => 'January', 'february' => 'February', 'march' => 'March', 'april' => 'April',
    'may' => 'May', 'june' => 'June', 'july' => 'July', 'august' => 'August',
    'september' => 'September', 'october' => 'October', 'november' => 'November', 'december' => 'December',
]">
    @foreach (['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'] as $month)
        <x-slot :name="$month">Reports for {{ ucfirst($month) }}.</x-slot>
    @endforeach
</x-widget.tabs>

Props

Other attributes, such as autocomplete or data-*, are passed through to the element. class styles the component's outer wrapper.

<x-widget.tabs>

Prop Default Description
id Required Required: names the tabs, their panels and their place in the URL (with remember). Unique on the page.
label null Names the tab list for screen readers ("Account settings").
tabs [] key => label, or key => ['label' => …, 'icon' => …, 'badge' => …, 'disabled' => bool, 'href' => …]. Each tab's panel is the named slot of the same key: <x-slot:profile>…</x-slot:profile>. With href on every tab they're links to other pages instead, and there are no panels.
value null The open tab's key; the first that isn't disabled by default. With wire:model, the bound property.
variant 'underline' underline, tinted (underlined, the open tab on a wash of the primary colour), pills, segmented (a track with the open tab raised in it), or vertical (stacked beside the panel).
remember false Keep the open tab in the URL (#settings=security), so a link, a reload or Back opens it.
name null What the tabs submit as, with a form around them: the open tab's key. Optional with wire:model.

Accessibility

All 8 examples above are checked with axe-core against the WCAG 2.2 A and AA rules, in the light theme and the dark one, both as the page draws and with each popover, dialog, toast and tooltip opened, on every change. A change that fails can't be merged. Where axe can't decide, such as contrast on SVG text, the test measures the colours itself instead of letting it pass.

Automated checks can't judge everything: how it sounds in a screen reader, and how it feels to use from the keyboard, still need a person. Check those on your own pages too.

Source

What bladewell:add tabs writes to your app with the default namespaces. Prefer to copy by hand? Take these files, plus the ones from the components it also adds , and the theme and base CSS.

resources/views/components/widget/tabs/index.blade.php Show
index.blade.php
resources/js/widget/tabs/index.js Show
index.js
app/View/Widget/ElementIds.php Show
ElementIds.php
app/View/Widget/FormField.php Show
FormField.php