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

Replace Accordion with Details and Card #2364

Closed
eirikbacker opened this issue Sep 2, 2024 · 9 comments · Fixed by #2824
Closed

Replace Accordion with Details and Card #2364

eirikbacker opened this issue Sep 2, 2024 · 9 comments · Fixed by #2824
Assignees
Labels
♿️ accessibility Issues related to accessibility css @digdir/designsystemet-css 🕵️ investigate Needs investigation react @digdir/designsystemet-react

Comments

@eirikbacker
Copy link
Contributor

eirikbacker commented Sep 2, 2024

Reasoning in #2364 (comment)


Description

  • Any opinions on Accordion often being used with only one Accordion.Item? Today we require that Accordion.Item is always wrapped in a grouping component, but can it occasionally not be a group? ☺️ See other systems operate with slightly different solutions; some call it Collapsible or Expandable so it is less related to it being in a group context.
  • And, there is currently no way to set that only one should be open at a time - all Accordion.Items can be opened and closed independently of each other, but maybe that is the intention? ☺️
  • Hover behind chevron: this is a design choice - marked that the designers in the Norwegian Food Safety Authority were confused by whether it was a UU requirement, but thoughts about hoover should be kept on only the chevron, or possibly the whole field?

Feedback from @Thunear :

  • I am often uses accordion with only 1 item on several different websites in the Digdir universe e.g. in the table of contents.
  • Will create an admin interface in the near future where I want only 1 accordion item in the left menu to be open at a time. Should perhaps be part of the component?
  • Hover on Chevron feels a bit weird, we should consider moving hover to the entire surface.

Response from @eirikbacker:

Agree - then think that Expandable is perhaps a better naming convention, as Accordion gives the expectation of grouping and one open at a time. I also think that Expandable can be used without any wrapper around it - it is entirely possible to get rounded edges etc. with pure CSS that looks for the previous and next element, so that:

<p>Some text before</p>
<Expandable>...<Expandable>
<Expandable>...<Expandable>
<p>Some text after</p>

will "connect with each other" and run as a group, while

<p>Some text before</p>
<Expandable>...<Expandable>
<p>Some text between</p>
<Expandable>...<Expandable>
<p>Some text after</p>

rendered separately.
The only annoying thing is that you then have to color each Expandable:

<p>Some text before</p>
<Expandable color="brand1">...<Expandable>
<Expandable color="brand1">...<Expandable>
<p>Some text after</p>

Alternatively, we can offer an Expandable.Group to have a quick way to wrap everyone, but that it is optional. It can be nice, but also a little assessment of how much we should do for people, because they will anyway often loop over content when they generate such groupings, and then they can put props there immediately (a bit the same as we landed on in ToggleGroup).

Regarding one open Expandable at a time; If we implement on top of native <details>, we can offer name="..." to group - when several Expandables have the same name, they are automatically linked together - in exactly the same way as input type="radio" works :relaxed :

@eirikbacker eirikbacker added react @digdir/designsystemet-react ♿️ accessibility Issues related to accessibility 🕵️ investigate Needs investigation css @digdir/designsystemet-css and removed 💡feature request labels Sep 2, 2024
@eirikbacker eirikbacker self-assigned this Sep 2, 2024
@eirikbacker eirikbacker moved this from 🔵 Inbox to 🏗 In progress in Team Designsystemet Sep 2, 2024
@eirikbacker
Copy link
Contributor Author

Related to #2363

@mrosvik
Copy link
Member

mrosvik commented Sep 3, 2024

ARIA skiller mellom "Accordion" og "Disclosure": https://www.w3.org/WAI/ARIA/apg/patterns/

@eirikbacker
Copy link
Contributor Author

...og HTML kaller det details - "the details disclosure element"
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details
Se også første notis fra W3C spesifikasjonen: https://html.spec.whatwg.org/multipage/interactive-elements.html#the-details-element:the-details-element-2

@eirikbacker eirikbacker changed the title Accordion: CSS principles and native details/summary Accordion naming convention? Sep 11, 2024
@eirikbacker eirikbacker moved this from 🏗 In progress to 📄 Todo in Team Designsystemet Sep 11, 2024
@mrosvik mrosvik added this to the V1 - Helhetlig komponentbibliotek milestone Sep 12, 2024
@eirikbacker eirikbacker removed their assignment Sep 18, 2024
@Barsnes
Copy link
Member

Barsnes commented Nov 22, 2024

If anything, I suggest going for Collapsible, if we don't want to use Accordion. Could also just use the native name for this, which I feel is the best option.

it is entirely possible to get rounded edges etc. with pure CSS that looks for the previous and next element, so that:

Yes, but what if the accordion is in a layout that adds gap between elements? We can't ensure that we can remove the spacing.
I suggest we still have a *.Group, to remove any confusion and possible issues.

Ref for Collapsible:
https://www.radix-ui.com/primitives/docs/components/collapsible
https://getbootstrap.com/docs/4.0/components/collapse/

@eirikbacker
Copy link
Contributor Author

eirikbacker commented Nov 22, 2024

Agreed ☺️ Like the .Group, and both Collapsible and Expandable are good alternatives in my opinion

@mimarz
Copy link
Collaborator

mimarz commented Nov 22, 2024

Why not call the Collapsible/Expandable for Details since we are using the details element?

Thinking out loud here:

For single use:

<Details>
  <Details.Summary> // or just <Summary>?
  …
<Details>

Now, if you want it to act like an Accordion

<Accordion>
  <Details>
  <Details>
  <Details>
</Accordion>

What do you guys think?

@eirikbacker
Copy link
Contributor Author

That could work 🙌 It correlates nicely with details / u-datails for HTML-users as well.
I think we might want Details.Group though?
Just a thought then; should Accordion also affect the behavior or only design?
In pure HTML, if the user wants only one details open at the time, they should add matching name to all <details> elements - aka. the "Accordion" wrapper does nothing to change behavior, it only affects design.

In React though, we can use context to add single/multiple open-at-the-time logic to Accordion: <Accordion multiple> vs <Accordion>, but this would then be a deviation between React/HTML. Also; one open-at-the-time should be avoided, so maybe it is okay to require actually setting name in React as well?

@mimarz
Copy link
Collaborator

mimarz commented Nov 22, 2024

That could work 🙌 It correlates nicely with details / u-datails for HTML-users as well. I think we might want Details.Group though? Just a thought then;

What would the Details.Group do?
We have no .Group sub-components now.
We moved away from .Group on Checkbox and Radio in favour of hooks.
First though here is we need to keep consistency with component usage/api.

should Accordion also
affect the behavior or only design? In pure HTML, if the user wants only one details open at the time, they should add matching name to all <details> elements - aka. the "Accordion" wrapper does nothing to change behavior, it only affects design.

In React though, we can use context to add single/multiple open-at-the-time logic to Accordion: <Accordion multiple> vs <Accordion>, but this would then be a deviation between React/HTML. Also; one open-at-the-time should be avoided, so maybe it is okay to require actually setting name in React as well?

Yeah, my though aswell. Accordion is just visual sugar and we expect people to use the "native" Details the way its meant to. If we want to provide some more DX, maybe a useAccordion hook, the same way we have for useRadioGroup which applies name on Radio.

Suggest we first try the most simplest approach, and then we can see how the DX feels and iterate on that.

@mimarz
Copy link
Collaborator

mimarz commented Nov 22, 2024

Meeting 22.11.2024 with @eirikbacker @Febakke @mimarz

We decided to try the following in regards to Accordion.

  • New component, Details and Details.Summary
  • Accordion will be removed in favour for composition of Details and Card
    • The only thing Accordion really did was a div with border and rounded corners around a list of <details> elements
    • Accordion without border can be achieved by just listing Details components
  • Accordion.Content will be removed and styling moved to Details
    • Animation might not work on some browsers but thats an okay tradeoff than having a superfluous Details.Content
  • Add stories to both Card and Details on composing them to make them behave like an accordion, with use of name

New Details component

<Details>
  <Details.Summary><Details>

New approach for equivalent <Accordion>

<>
  <Details>
  <Details>
  <Details>
</>

New approach for equivalent <Accordion border>

<Card>
  <Details>
  <Details>
  <Details>
</Card>

@mimarz mimarz changed the title Accordion naming convention? Replace Accordion with Details and Card Nov 22, 2024
@eirikbacker eirikbacker moved this from 📄 Todo to 🏗 In progress in Team Designsystemet Nov 22, 2024
eirikbacker added a commit that referenced this issue Nov 26, 2024
- Fixes #2364
- `data-color` throws an type error in `showcase.tsx` but this is not
related to this branch
- Color of details/cards will be adjusted by design, but they wanted to
move forward with the currently implemented logic for now

---------

Co-authored-by: Tobias Barsnes <tobias.barsnes@digdir.no>
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in Team Designsystemet Nov 26, 2024
@mrosvik mrosvik modified the milestones: Helhetlig komponentbibliotek, V1 - Lansering Jan 28, 2025
mimarz pushed a commit that referenced this issue Feb 21, 2025
- Fixes #2364
- `data-color` throws an type error in `showcase.tsx` but this is not
related to this branch
- Color of details/cards will be adjusted by design, but they wanted to
move forward with the currently implemented logic for now

---------

Co-authored-by: Tobias Barsnes <tobias.barsnes@digdir.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
♿️ accessibility Issues related to accessibility css @digdir/designsystemet-css 🕵️ investigate Needs investigation react @digdir/designsystemet-react
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

5 participants