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

New Feature: Accordion - expanded state control #82

Open
ncoetzer opened this issue Aug 18, 2021 · 3 comments
Open

New Feature: Accordion - expanded state control #82

ncoetzer opened this issue Aug 18, 2021 · 3 comments
Assignees
Labels

Comments

@ncoetzer
Copy link

Is your feature request related to a problem? Please describe.
We've recently had a request from a client (Campbell's) to extend the accordion component with functionality to control its initial expanded state upon page load. By default, this feature is not built-in and would probably have to be added manually (which I'm almost sure has been done several times in the past). This seemed to be a handy feature that could benefit other projects/clients as well.

Describe the solution you'd like
As a solution, we've implemented ToggleControls on two levels:

  • A global toggle that controls the expanded state for all accordion items. When the global switch is enabled, all inner child items will inherit the setting
    77ce627f07045f77613575d23c6d54f0

  • Item-specific toggle that only controls its own expanded state. This option is only available if the global option has been disabled
    77e3e91999ab20ab3dfd4d1bd78d4ddb

As a result, not only would administrators have more control to customize the initial state of the accordion, but it would also improve the user experience in the editor at the same time.

@devinle
Copy link
Contributor

devinle commented Aug 18, 2021

Hey @ncoetzer thanks for opening this issue.

A few questions, or rather, discussion points:

As a user, when clicking to expand an accordion item, the accordion should ...

  • collapse all other items except for the one clicked?
  • OR keep all other expanded items opened?
  • AND update the URL with a hash for direct linking? (<--not sure I would build this one out, since updating the URL might be making too many assumptions. But if there were an option or setting to do so, it might be a nice touch)

As an editor, when enabling the toggle "Expand by default" on an item, the accordion should ...

  • toggle off the Expand by default setting on siblings (other accordion items)?
  • OR allow for multiple expanded items opened?

The multiple vs singular items mentioned in the User and Editor criteria definitely relate. Oftentimes I'm on the fence with either only allowing a single accordion item to remain opened–but this can often force the collapse of other accordion items the user may still want opened.

Overall, I like your approach!

References:

@ncoetzer
Copy link
Author

Thanks, @devinle really appreciate your feedback on this.

As a user, when clicking to expand an accordion item, the accordion should ...

The current behaviour of the accordion component is to keep all other expanded items open. I'm also with you on the fence here. The behaviour of only allowing a single accordion open at a time feels kind of forced. Perhaps this could be an additional option or setting e.g. "Tabbed" or "Multi-select", which would further allow the user to select the type of accordion they would want. However, this would interfere with the toggle approach, since more than one item could be expanded on load.

As an editor, when enabling the toggle "Expand by default" on an item, the accordion should ...

With my approach, the toggle for each individual item only becomes available and effective if the global option is disabled. The purpose of the global option is a quick way to force the behaviour on all items, regardless of their individual setting. Both the global and individual item options are by default set to false. Only if the global option is false/off, will the option become available on each individual item, otherwise, it inherits the global setting.
I made a short screen recording to showcase what I've done on a past project for Campbell's Corporate, that might explain things a bit better 😉

Screen.Recording.2021-08-19.at.10.08.42.AM.1.mp4

@ncoetzer
Copy link
Author

We'll preferably introduce this new feature to the component here (CSS + JS) and the block library (InspectorControls) in tandem. This will ensure the new settings are also available to administrators in the admin.

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

No branches or pull requests

4 participants