Skip to content

Hide/Show Component/Section when tab is active #15115

Answered by leandrocfe
jandomos asked this question in Help
Discussion options

You must be logged in to vote

try this

Section::make()
    ->schema([])
    ->visible(fn (Page $livewire): bool => $livewire->tab === '-tab1-tab'),
Tabs::make('Tabs')
    ->extraAlpineAttributes(['x-effect' => '$dispatch(\'update-tabs\', { tab: tab })'])
    ->tabs([
        Tabs\Tab::make('Tab1')
            ->schema([]),
        Tabs\Tab::make('Tab2')
            ->schema([]),
    ])
    ->activeTab(1)
    ->persistTabInQueryString(),

YourPage.php (Create, Edit..)

use Livewire\Attributes\On;
...

public $tab = null;

#[On('update-tabs')]
public function updateTabs($tab): void
{
    $this->tab = $tab;
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jandomos
Comment options

Answer selected by jandomos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants