filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
19.3k stars 2.97k forks source link

Side menu collapsing issue #11789

Closed VanDerRomio closed 8 months ago

VanDerRomio commented 8 months ago

Package

filament/filament

Package Version

v3.2.25

Laravel Version

v10.45.1

Livewire Version

v3.0

PHP Version

PHP 8.2

Problem description

Navigation groups dont collapse

Screenshot_20240310_165320

Added collapsed() to NavigationGroup and set sidebarFullyCollapsibleOnDesktop() in Panel - dont collapse group. View cache or browser local storage is clear.

Expected behavior

to be collapsed

Steps to reproduce

in app\Providers\Filament\AdminPanelProvider.php


namespace App\Providers\Filament;

use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Pages;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Widgets;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->default()
            ->id('admin')
//            ->domain('admin.localhost')
            ->path('admin')
            ->login()
            ->colors([
                'primary' => Color::Amber,
            ])
            ->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
            ->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
            ->pages([
                Pages\Dashboard::class,
            ])
            ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
            ->widgets([
                Widgets\AccountWidget::class,
                Widgets\FilamentInfoWidget::class,
            ])
            ->middleware([
                EncryptCookies::class,
                AddQueuedCookiesToResponse::class,
                StartSession::class,
                AuthenticateSession::class,
                ShareErrorsFromSession::class,
                VerifyCsrfToken::class,
                SubstituteBindings::class,
                DisableBladeIconComponents::class,
                DispatchServingFilamentEvent::class,
            ])
            ->authMiddleware([
                Authenticate::class,
            ])
            ->collapsibleNavigationGroups()         // not working
            ->sidebarFullyCollapsibleOnDesktop()    // not working
            ->sidebarCollapsibleOnDesktop();        // not working
    }
}

in app\app\Filament\Resources\CategoryResource.php

<?php

namespace App\Filament\Resources;

use App\Filament\Resources\CategoryResource\Pages;
use App\Models\Category;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class CategoryResource extends Resource
{
    protected static ?string $model = Category::class;

    protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

    public static function getNavigationGroup(): string
    {
        return __('models.Product.navigation_label');
    }

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\TextInput::make('name')
                    ->maxLength(255)
                    ->required(),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('name')
                    ->searchable(),
            ])
            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\EditAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ]);
    }

    public static function getRelations(): array
    {
        return [
            //
        ];
    }

    public static function getPages(): array
    {
        return [
            'index'     => Pages\ListCategories::route('/'),
            'create'    => Pages\CreateCategory::route('/create'),
            'edit'      => Pages\EditCategory::route('/{record}/edit'),
        ];
    }
}

Reproduction repository

https://github.com/VanDerRomio/filamentphp-group/tree/main

Relevant log output

No response

danharrin commented 8 months ago

I added:

->navigationGroups([
    NavigationGroup::make('Users')
        ->collapsed(),
])

Cannot reproduce:

https://github.com/filamentphp/filament/assets/41773797/afcef2a5-222c-4854-9c6a-5136e814c061

VanDerRomio commented 8 months ago

if I set it to "collapsed" - then it has to be collapsed every time i reload the page in the browser, and it doesn't

danharrin commented 8 months ago

That is not what the behaviour does, it is collapsed when you first visit the page, and then your preference is remembered

VanDerRomio commented 8 months ago

ok, so how can I reset it from php?

danharrin commented 8 months ago

It's controlled by JS, you'd need to inject a script in a render hook to alter the local storage