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

In accordion I cannot set all items to be closed by default. #219

Open
algsupport opened this issue Feb 7, 2022 · 4 comments
Open

In accordion I cannot set all items to be closed by default. #219

algsupport opened this issue Feb 7, 2022 · 4 comments

Comments

@algsupport
Copy link

algsupport commented Feb 7, 2022

What steps will reproduce the problem?

Create an accordion widget with any number of groups.

What's expected?

All accordion groups to be closed by default.

What do you get instead?

First group is always rendered showing not matter what options I set.

Additional info

Q A
Yii vesion Latest
PHP version 8.0
Operating system Windows 10

Hi everyone,

I am trying to created an accordion widget that by default has all it's groups not showing, but instead the first group is always showing by default.

I tried reading the source code from accordion.php it seems that the BC fix is enforcing this behavior without any option to configure it.

Did I miss anything?
Appreciate your input.
Regards

@simialbi
Copy link
Contributor

simialbi commented Feb 7, 2022

What about setting

[
    'items' => [
        [
            // [...],
            'expand' => false
        ]
    ]
]

@algsupport
Copy link
Author

algsupport commented Feb 7, 2022

@simialbi thank you for your response. I believe I have tried it.
I will check again and update you, but I would like to get your attention to these lines of code:

$expanded = array_search(true, ArrayHelper::getColumn(ArrayHelper::toArray($this->items), 'expand', true));
foreach ($this->items as $key => $item) {
if (!is_array($item)) {
$item = ['content' => $item];
}
// BC compatibility: expand first item if none is expanded
if ($expanded === false && $index === 0) {
$item['expand'] = true;
}

If I am not mistaken, it means that if none of the items have expand set to true, then set expand to true for the first item/group.
Please correct me if I am wrong.

Thank you for your time
Regards

PS. I have already fixed the issue in my code. I just extended the class and overridden the function and it works for me.

@simialbi
Copy link
Contributor

simialbi commented Feb 8, 2022

@algsupport you're right, it's done because of compatibility with yii\bootstrap\Collapse

@algsupport
Copy link
Author

@simialbi I got that. But I think there should be a way to explicitly disable that behavior.

Regards

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

2 participants