laravel / nova-issues

554 stars 34 forks source link

collapsedByDefault() not working #6521

Closed andersespedalen closed 3 weeks ago

andersespedalen commented 3 weeks ago

Description:

I expected adding ->collapsedByDefault() to MenuSection would keep the section collapsed on page load or login, but there is no change. With using ->collapsable() as well together with ->collapsedByDefault() or not makes no difference.

Detailed steps to reproduce the issue on a fresh Nova installation:

NovaServiceProvider:

                MenuSection::make('Customer', [
                    MenuItem::resource(\App\Nova\Customer::class),
                    MenuGroup::make('Advanced', [
                        MenuItem::resource(\App\Nova\CustomerPollData::class),
                        MenuItem::resource(\App\Nova\Login::class),
                        MenuItem::resource(\App\Nova\BetaTester::class),
                    ])
                        ->collapsable()
                        ->canSee(function (Request $request) {
                            return $request->user()->usertype >= User::SUPPORT;
                        }),
                ])
                    ->icon('user')
                    ->collapsable()
                    ->collapsedByDefault()
                    ->canSee(function (Request $request) {
                        return $request->user()->usertype >= User::OPERATOR;
                    }),
jeremynikolic commented 3 weeks ago

Hi @andersespedalen, thanks for reaching out to us about this issue ๐Ÿ™

Regarding the collapseByDefault, be aware that Nova stores collapsable state in localStorage for restoring it between visits. The collapseByDefault therefore has effect only if there is not previous collapsed stats in local storage for that menu section.

andersespedalen commented 3 weeks ago

Hi @jeremynikolic

Thanks for the quick reply. I tested this and can confirm what you say.

In this case the way I see it, new users (or those who clear local storage) will see the MenuSection as collapsed until they toggle/untoggle. Also when adding new menu-items (using collapsedByDefault), these will by default show as collapsed.

There is no way to force a collapse for example for each session?

jeremynikolic commented 3 weeks ago

No problem ๐Ÿ˜„

Currently there is no way to disable this localStorage behavior but please feel free to submit the idea in the discussions. We frequently go through them and look at implementing them when feasible and aligned with Nova's vision ๐Ÿ‘

I'll be closing this issue, take care ๐Ÿ™