eminiarts / nova-tabs

Laravel Nova Tabs Package

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

proposal: withSelectedTab

otrsw opened this issue · comments

Firstly thank you for a really great component! We use it extensively. We do have one recurring request from our users, and it is so important I would be willing to contribute/sponsor/fund the addition of this feature.

Basically, when updating a resource, what we need is some way to set the "selected tab" since in edit view it always defaults to the first tab. We use the component in conjunction with a "wizard" type update process, where we dynamically add tabs after each update to guide a user through a multistep update of a resource. This works beautifully, except when moving to the "next" step, the new tab is usually at the end, and the first tab is always selected, forcing the user to click on the last tab to continue editing where they left off.
The extra click is no big deal for us - but for some users that just seems a "bridge too far" and we have given up trying to "ignore" the problem...

I would be happy to explain more if required - here is a snippet of code for some context, with the "desired" withSelectedTab method

    //A slightly modified fields method basically ensures we have the model...

    public function fields(Model $model, NovaRequest $request, $context, $update = true)
    {
        $tabs = [];
        $s = 1;
        $totalSteps = count($this->sections);
        foreach ($this->sections->sortBy('order') as $section) {
            $lastTab = $model->step;
            if ($s <= $lastTab) {
                $tabLabel = __($section->name);

                $tabs[] = Tab::make($tabLabel, [
                    ...$section->fields($request, $context, $update)
                ]);
            }
            $s += 1;
        }

        return [

            //$tabLabel would have the name of the last tab
            Tabs::make('Questionnaire', $tabs)->withSelectedTab($tabLabel),

        ];
    }