Skip to content

refactor!: re-implement details and accordion structure - #5093

Merged
web-padawan merged 9 commits into
masterfrom
refactor/details-accordion-revamp
Dec 7, 2022
Merged

web-padawan merged 9 commits into
masterfrom
refactor/details-accordion-revamp

Conversation

@web-padawan

@web-padawan web-padawan commented Dec 1, 2022 •

Copy link
Copy Markdown
Member

Description

This is a first part of re-implementing the vaadin-details and vaadin-accordion components for V24.

Some things are still marked as TODOs, especially logic for setting aria-controls + aria-labelledby.
I'm going to address those in a separate PR because this one is already way too big.

Part of #5077
Fixes #412
Fixes #90

Overview

This PR contains several breaking changes that aim to improve accessibility for two components.

<vaadin-details>

  1. Added vaadin-details-summary which has role="button" and uses ButtonMixin internally,
  2. Removed element with role="heading" from Shadow DOM of vaadin-details as not needed,
  3. TODO: add summary property that can be used as label property in vaadin-checkbox etc.

<vaadin-accordion>

  1. Decoupled vaadin-accordion-panel from vaadin-details so that styles won't apply to both,
  2. Changed to use vaadin-accordion-heading element with role="heading" in the summary slot,
  3. The heading element now uses native <button> in Shadow DOM with delegatesFocus: true.

Type of change

  • Breaking change

Note

Decided to keep summary slot in case of vaadin-accordion-panel in order to ensure that on the Flow side, the AccordionPanel can still have the backwards compatible API, and maybe even extend Details if needed.

@web-padawan
web-padawan force-pushed the refactor/details-accordion-revamp branch 6 times, most recently from 3dd67aa to 7fda924 Compare December 2, 2022 07:05
* The WAI ARIA Best Practices also recommend setting `aria-level` depending
* on what level the headings are. It is hard to determine the level of a heading
* algorithmically, and setting it is not strictly required to have an accessible
* accordion. To keep things easier to use, this element does not set `aria-level`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning to add an API for it on the flow side?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the idea. For each AccordionPanel, we would create an instance of AccordionHeading on the server side and then expose it e.g. getHeadingComponent() API, to enable setting aria-level e.g. like this:

Accordion accordion = new Accordion();
AccordionPanel panel = accordion.add("Heading text", new Div());
panel.getHeadingComponent().getElement().setAttribute("aria-level", "3");

Does that sound reasonable? Or do you have any other suggestions on how the API might look like?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for already considering it! This would reduce the boilerplate I've created in my apps where I've manually added h* elements inside the header.

I'm totally fine with the API, but I'm wondering if people would find / use them. Would it make sense to have something like an AriaLevel enum with 1-6 allowing to create constructors like:

new Details(String caption, Component content) 

new Details(String caption, AriaLevel headingLevel, Component content) 

new Details(String caption, AriaLevel headingLevel, Component content) 

// AriaLevel could be optional / nullable allowing it to be not set if not present like in the first constructor

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could consider it for Accordion. As for Details, I'm inclined to follow the suggestion from #90:

There are three possibilities for resolving this. The first is to remove role="heading" from the component. While it is valid for a heading to be used in this way, it is more common in an Accordion pattern. Details patterns, such as the W3C WAI-ARIA Authoring Practices 1.1 Disclosure (Show/Hide), do not wrap the button control in a heading.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally valid! Just checked my application and I have only accordions in use as of now, so I'm totally fine with your idea 👍

@web-padawan
web-padawan force-pushed the refactor/details-accordion-revamp branch from 7fda924 to ca5caf5 Compare December 7, 2022 10:19
@web-padawan
web-padawan removed the request for review from vursen December 7, 2022 13:44
@sonarqubecloud

sonarqubecloud Bot commented Dec 7, 2022

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@web-padawan
web-padawan merged commit aba1bb3 into master Dec 7, 2022
@web-padawan
web-padawan deleted the refactor/details-accordion-revamp branch December 7, 2022 13:47
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 24.0.0.alpha6 and is also targeting the upcoming stable 24.0.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[accordion] Styles overrides seem to mix with vaadin-details details: heading level cannot be specified for elements with heading role

4 participants