Default Active Tab Not Working for Tab Filter

In my List page I have a Tabs filter for each day of the week. But when I try to set the default active tab, it just wont work. The default active tab is always the first one no matter what I return from getDefaultActiveTab()
public function getTabs(): array
{
return [
'Sunday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Sunday)),
'Monday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Monday)),
'Tuesday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Tuesday)),
'Wednesday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Wednesday)),
'Thursday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Thursday)),
'Friday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Friday)),
'Saturday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Saturday)),
];
}

public function getDefaultActiveTab(): string | int | null
{
return 'Tuesday';
}
public function getTabs(): array
{
return [
'Sunday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Sunday)),
'Monday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Monday)),
'Tuesday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Tuesday)),
'Wednesday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Wednesday)),
'Thursday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Thursday)),
'Friday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Friday)),
'Saturday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Saturday)),
];
}

public function getDefaultActiveTab(): string | int | null
{
return 'Tuesday';
}
3 Replies
LeandroFerreira
LeandroFerreira15mo ago
what about this?
public ?string $activeTab = 'Tuesday';
public ?string $activeTab = 'Tuesday';
tuto1902
tuto1902OP15mo ago
let me try, one sec... Yeah, that works with static values. But I want to set it dynamically using Carbon::today()->format('l') I can see how overriding the mount() method would help, I just don't know if that's the best way to do it Oh, never mind. I just did a composer update and now it works 🤦🏼‍♂️
tuto1902
tuto1902OP15mo ago
I thought it was strange that the ListRecords base class wasn't using the getDefaultActiveTab method in mount(), and now I know why
Want results from more Discord servers?
Add your server