Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: withSelectedTab #274

Open
otrsw opened this issue Feb 11, 2023 · 0 comments
Open

proposal: withSelectedTab #274

otrsw opened this issue Feb 11, 2023 · 0 comments

Comments

@otrsw
Copy link

otrsw commented Feb 11, 2023

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),

        ];
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant