Hi.
Its more than likely a me problem, but I’m trying to create Tabs for a component using alpine but I want it to grab the select tab from the component, i.e when theres #my_tab selected in the route, it opens that tab.
So far I have::
// View
<div x-data="{selectedTab: @entangle('selectedTab')} ">
// Tab Nav
<button wire:click=" selectTab('tab-1') ">
My Tab 1
</button>
<button wire:click=" selectTab('tab-2') ">
My Tab 2
</button>
<div x-show="selectedTab === 'tab-1'">
// Stuff goes here
</div>
<div x-show="selectedTab === 'tab-2'">
// Stuff goes here
</div>
</div>
// Component
public $selectedTab = 'dispatch';
public function selectTab($tab)
{
$this->selectedTab = $tab;
}
But for some reason (which is probably obvious to most) It wont change the tab!
Eventually I’m wanting it so that when I set the tab through the route if needed so that when the page is refreshed it stays on the same route. So i’d have to set it so the buttons are a href and add a #
Any help or pointers where to look would be great