amp-accordion: auto-collapse sections that are not ancestors of a section
In a menu, the possibility to automatically close 'section's that are not "needed" when using nested amp-accordeons is required. The two main reasons:
- When jumping from a section of a menu to an other, the user is usually only interested by the descendants, not the whole menu tree.
- The practical reason is to prevent a menu to expand in length and requiring scrolling on mobile devices.
In summary, the request is to have the option to set the following behaviors in nested amp-accordeons:
- When a 'section' is expanded, to close all the 'section's that aren't a direct ancestor of it in the amp-accordeons tree.
- When a 'section' is closed, to restore the default state of its children or to close all of them.
/cc @sriramkrish85 @ericlindley-g
Agreed that this would be useful as an option—some complications (after sync'ing w/ @sriramkrish85) include:
• Currently there is no animation for the expand/collapse action. This means that it may be difficult for the user to track the behavior of the interface if multiple items are collapsing at the same time that their target element is expanding. • There is no scrolling adjustment when amp-accordion closes or opens, which means if a large enough (or large enough set of) amp-accordion(s) closes above the current viewport, the content inside the viewport could shift dramatically (even entirely out of view) • Needs some way for multiple amp-accordion elements to communicate with each other (could be a parent element with an attribute something like "auto-collapse-children")
Slotting into the backlog to weigh against other priorities before pulling this item into a sprint, but open to ITI's as always
I looked into this a little bit and tried to prototype it by registering a collapse action on a parent collapse event. But it looks like that approach does not work because we can't register actions on sections (we can only register actions on implementers of BaseElement), so an auto-collapse-children attribute looks like the way this would go. This is actually a relatively self-contained feature, and could be a GFI / contribution candidate for an experienced engineer. =)
So it seems like the FR here only applies to nested accordions.
When a 'section' is expanded, to close all the 'section's that aren't a direct ancestor of it in the amp-accordions tree. When a 'section' is closed, to restore the default state of its children or to close all of them.
Given that there is currently no limit in terms of how many levels of nesting you can do with accordions, and that we already have expand-single-section and animating an accordion per
- https://github.com/ampproject/amphtml/issues/11359
- https://github.com/ampproject/amphtml/issues/11358
Do we still need this? Can we solve this problem using expand-single-section and animate on all the nested accordions? Or is there a legitimate use case for expanding multiple upper layer accordion sections, and then closing the adjacent ancestors on opening a nested child accordion?
@devnullzero
closing given expand-single-section and #8641