question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

💡 Proposal - Accordion Component

See original GitHub issue

Forma 36 contribution proposal

The problem

In the feature that I’m working on we had to create a FAQ section for a page. But the content of around 6 questions is quite long to be always on the page, also a user may want to know about one thing only so scrolling over the other 5 questions would be annoying or make the user miss what they a looking for.

The proposed solution

Let’s create an Accordion component. It would also need an <AcordionHeader /> and an <AcordionPanel />

prototype

Anatomy

Accordion Header: Label for or thumbnail representing a section of content that also serves as a control for showing, and in some implementations, hiding the section of content. Accordion Panel: Section of content associated with an accordion header. (taken from WAI-ARIA)

Chevron variation

We could have a prop to define two different alignments for the chevron

Chevron Orientation

Hover/Focus state

For hover and focus state we can use the same styles we use in the naked button

Focus state

Considering the case where the accordion has a gray background, this is how it would look Focus state GRAY

Usage

The component allows other components to be passed as a title for the accordion, but it is better to avoid abusing this feature. In most cases, a Heading or Subheading component will be enough. It’s worth to point out that there is a case in Contentful’s webapp where we have a ... button in an accordion header. I propose that his pattern should not be supported because it harms the accessibility of the component. The reason for this can be checked in the W3 docs for accordions

  • The title of each accordion header is contained in an element with role button.
  • Each accordion header button is wrapped in an element with role heading that has a value set for aria-level that is appropriate for the information architecture of the page.
    • If the native host language has an element with an implicit heading and aria-level, such as an HTML heading tag, a native host language element may be used.
    • The button element is the only element inside the heading element. That is, if there are other visually persistent elements, they are not included inside the heading element.

DO and DONTS

Important requirements

  • Accessibility following WAI-ARIA
  • Possibility to pass other components to the Accordion Header

Breaking changes

Uhmmm I don’t think there is any breaking change, but maybe we would release it as an alpha component first

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
joaoramoscommented, Jul 20, 2020

Good one! I advise against collapsing sections automatically when one section gets selected, if you ever consider introducing that behaviour. Otherwise, I’d move forward 🚀

1reaction
gui-santoscommented, Aug 3, 2020

@mshaaban0 oh I used I bunch of aria attributes, let me open my PR and then you point me where I can use summary and detail, thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Accordion – Carbon Design System
The accordion component delivers large amounts of content in a small space through progressive disclosure. The header title give the user a high...
Read more >
How To Build an Accordion Component with React
In this article you will learn how to build an Accordion (show/hide) component in React.
Read more >
React Accordion - Web UI Documentation
An Accordion is a content area which can be collapsed and expanded. It can be used to group or hide complex regions to...
Read more >
Accordion Design: UI Best Practices & Examples - HubSpot Blog
An accordion is a menu composed of vertically stacked headers that reveal more details when triggered (often by a mouse click).
Read more >
Accordion Component | Adobe Experience Manager
The Core Component Accordion component allows for the creation of a collection of components, composed as panels, and arranged in an accordion ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found