gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

New block: Accordion block

Open mapk opened this issue 6 years ago • 134 comments

There's been a few requests for an Accordion block in core. Let's start exploring how this looks.

Requirements

  • Pure CSS.
  • Add accordion headers with arrow icons.
  • Allow any block to be added within an accordion section.

Is the accordion section simply a Group block that is able to be collapsed? Basically it would work similarly to the Settings sidebar sections.

accordion

Kudos to @melchoyce for this idea. Some examples she shared recently:

https://codepen.io/raubaca/pen/PZzpVe https://codepen.io/vinsongrant/pen/qbGKed https://codepen.io/abergin/pen/ihlDf

mapk avatar Apr 14 '20 19:04 mapk

Great! Yeah this is needed. I have seen a few requests over a longer period of time asking for an accordion block.

paaljoachim avatar Apr 15 '20 10:04 paaljoachim

If there is a fallback for IE, it could be a details element, reducing the markup drastically. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details

carolinan avatar Apr 15 '20 12:04 carolinan

Actually accordions don't need CSS, JS etc... We could simply use a <details> HTML element.

<details>
  <summary>This is the accordion title</summary>
  This is the accordion content
</details>

^ The above code would render like this:

This is the accordion title This is the accordion content

Coincidentally I started building a details block yesterday and it works fine that way.

We can add options to change the styling of the triangle etc if needed, and there's some extra info on this article

Note: accordions built this way are 100% accessible and they just work because native-HTML :smile:


Edit: It looks like I was writing this comment at the same time as @carolinan above :laughing:

aristath avatar Apr 15 '20 12:04 aristath

We could do a render fallback on the server for IE, or also consider not doing anything (it'll still render the content, just expanded by default).

mtias avatar Apr 16 '20 13:04 mtias

having it expanded by default in IE is not a big issue... As long as it renders and looks OK I don't think we should add any extra scripts etc to make IE behave like modern browsers. Supporting IE is not the same as making it look & behave identically :+1:

aristath avatar Apr 16 '20 13:04 aristath

Here are some plugin examples that use accordion blocks. Twenty Twenty. Gutenberg plugin activated.

Atomic Blocks https://wordpress.org/plugins/atomic-blocks/

Backend: Atomic-Blocks-Accordion

Title selected: Atomic-Blocks-Accordion-title-selected

Content selected: Atomic-Blocks-Accordion-content-selected

Frontend: Atomic-Blocks-Accordion-frontend


Co Blocks https://wordpress.org/plugins/coblocks/

Backend.

Title is selected. Co-Blocks-Accordion-1

Content is selected: Co-Blocks-Accordion-2

To add a new accordion one clicks the Inserter area similar to the Group Block.

Frontend: Co-Blocks-Accordion-frontend


Accordion Blocks by Phil Buchanan https://wordpress.org/plugins/accordion-blocks/

Backend.

Title selected. Accordion-Block-Phil-1

Content selected. Accordion-Block-Phil-2

Frontend. There is a minus on the right side when the accordion is open. When the accordion is closed there is a + sign. Accordion-Block-Phil-frontend

paaljoachim avatar May 30 '20 22:05 paaljoachim

It's worth noting that using heading elements in the <summary> is valid, and that would be the correct way to handle a lot of use-cases for accordions like step-by-step how-to articles.

Should the Accordion block have an option to switch the contents of the <summary> from plain (no inner elements other than text) to different heading levels (similar to the options provided in the Heading block); or should the <summary> be an entire InnerBlocks area where you can insert whatever typography-related block you want?

I'm currently leaning towards the former solution, since it's less complicated, and it's much easier to migrate from that to the latter solution in the future than to go the other way around.

ZebulanStanphill avatar Jun 03 '20 15:06 ZebulanStanphill

The only thing with IE11 and <details> HTML element is they are expanded by default as mentioned. The problem with that is it defeats the purpose of toggles.

LukaszJaro avatar Jun 03 '20 17:06 LukaszJaro

The only thing with IE11 and <details> HTML element is they are expanded by default as mentioned. The problem with that is it defeats the purpose of toggles.

IE11 doesn't break with a <details> element... and sure, it's not the same as it is in a modern browser but that's not a dealbreaker. Nobody on IE expects to see the same thing they'd see when using Firefox/Chrome/Brave/Whatever. Different browsers exists for different people, different tastes and needs or limitations. If they use IE, then the rest of the planet shouldn't suffer for it. A workaround could be implemented for IE by loading a conditional script that would tweak the behaviour, but... is it really worth it? Adding extra html & JS in other browsers just to make IE work would do a lot more damage overall, and we can't really move forward if we keep looking at a broken thing from 7 years ago. They can still see the content, they can read everything, things are properly styled, just not collapsed by default.

aristath avatar Jun 03 '20 18:06 aristath

I understand what your saying @aristath I just have a very strange requirements with a project right now which only supports IE11 ! yea...it is an internal site like a intranet type. The content editor wanted some toggles..

And there is still years of support for IE11 :(

https://death-to-ie11.com/

LukaszJaro avatar Jun 03 '20 19:06 LukaszJaro

This issue and related PR were discussed today by the Accessibility team.

The team suggests to not use the <details> element for this scenario, and instead follow the ARIA Authoring Practices implementation for an accordion component

For more details on why <details> is not a suitable element, please see:

  1. https://daverupert.com/2019/12/why-details-is-not-an-accordion/
  2. https://adrianroselli.com/2019/04/details-summary-are-not-insert-control-here.html

As always, please feel free to ping the team in the #accessibility Make WordPress Slack channel if there are further questions or comments.

enriquesanchez avatar Jul 17 '20 16:07 enriquesanchez

Here's an iteration on the Accordion block.

Accordion

mapk avatar Jul 17 '20 18:07 mapk

That looks pretty good. One thing we'll need to make sure to include in the block's toolbar is a way to switch the HTML element of the heading, including h1-h6 options, plus maybe even p? We should be able to extract the heading level control from the Heading block and reuse it here.

ZebulanStanphill avatar Jul 23 '20 20:07 ZebulanStanphill

Here's a prototype of how I imagine this block working.

accordion

  • It uses similar block interactions as the Group and Heading blocks.
    • The Accordion heading allows a heading level change.
    • The large + Inserter button below works like the Group block.
  • The heading is editable on focus of the Accordion block.
  • Adding content to the collapsable region requires clicking the + Inserter to add a block.
  • When resting, the Accordion block collapses to hide the content region.
  • When focused, the Accordion block open to show the content.

mapk avatar Jul 28 '20 22:07 mapk

Some recent design feedback lead me to add a couple Style Variations.

Default

default

Style Variation 1

variation 1

Style Variation 2

variation 2

mapk avatar Jul 29 '20 16:07 mapk

Further design feedback from @melchoyce suggested that we just drop a Paragraph block into the content area rather than a big + button. The flow would look something like this.

accordion-with-p

mapk avatar Jul 29 '20 17:07 mapk

Recent design feedback:

Arrows

The arrows need to be oriented differently. Rather than up/down, they should be right/down.

lf-arrows

Style variations

There's some question as to whether or not the variations above make sense to include as style variations. I'm waffling back and forth on this one. They are "style" variations that only manipulate styling... so that makes sense to me.

Default variation

Should the above Style Variation 2 actually be the default because there's basically no styling? It might make it easier to themes to apply their own styles with that as the default.

mapk avatar Jul 31 '20 17:07 mapk

Yeah, I'd favor a default style that's easy for themes to override.

ZebulanStanphill avatar Aug 01 '20 04:08 ZebulanStanphill

Here is a draft PR for the Details Block: https://github.com/WordPress/gutenberg/pull/23940 There is some crossover of the Accordion and the Details Blocks.

paaljoachim avatar Aug 03 '20 08:08 paaljoachim

Looking good. Liking the iterations so far and how this is evolving. Some feedback:

  • Add the interaction/flow for adding an additional accordion section
  • Add the interaction/flow for adding an additional block within the accordion content
  • Add block settings for accordion

To summarize above: I think it would be good to see the full block adding flow in context with the sidebar and its settings

  • I would also push the styles a bit more. Right now they are very subtle and I wouldn't consider them a different style, more just removing/adding background+border colors. Try playing more with layout, spacing, position of elements. Similar to this approach: https://github.com/WordPress/gutenberg/issues/22071#issuecomment-624637501

kellychoffman avatar Aug 05 '20 21:08 kellychoffman