Skip to content

feat: add HasAriaRole interface - #24782

Merged
tltv merged 2 commits into
mainfrom
feat/has-aria-role
Jun 26, 2026
Merged

tltv merged 2 commits into
mainfrom
feat/has-aria-role

Conversation

@web-padawan

@web-padawan web-padawan commented Jun 23, 2026 •

Copy link
Copy Markdown
Member

Added a shared HasAriaRole mixin interface so that components like Card, Badge, Dialog, and Popover could implement a single common contract instead of duplicating the logic.

The interface is placed next to HasAriaLabel in com.vaadin.flow.component and follows the same pattern: attribute-based storage, null clears the attribute, and the getter returns an Optional.

Part of vaadin/flow-components#9489


🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Artur-

Artur- commented Jun 23, 2026

Copy link
Copy Markdown
Member

Are there use cases where you implement HasAriaLabel and not HasAriaRole or vice versa? Or should they be the same interface?

@github-actions

github-actions Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

 1 454 files  +1   1 454 suites  +1   1h 30m 2s ⏱️ +46s
10 283 tests +4  10 215 ✅ +4  68 💤 ±0  0 ❌ ±0 
10 755 runs  +4  10 686 ✅ +4  69 💤 ±0  0 ❌ ±0 

Results for commit a3cca47. ± Comparison against base commit 49b01a9.

♻️ This comment has been updated with latest results.

@web-padawan

Copy link
Copy Markdown
Member Author

Are there use cases where you implement HasAriaLabel and not HasAriaRole or vice versa? Or should they be the same interface?

Most of field components implement HasAriaLabel but do not provide an option to override a role, as they have native element for it such as <input type="checkbox">, <textarea> etc. So let's keep these separate.

* @return an optional ARIA role of the component if no ARIA role has been
* set
*/
default Optional<String> getAriaRole() {

@sissbruecker sissbruecker Jun 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Getters in HasAriaLabel return Optional, so this matches those for consistency. Other than that returning an optional seems atypical for mixin interfaces that just set properties / attributes, and I can't see a clear purpose on why that is necessary in this specific case (or for HasAriaLabel). Maybe worth considering to return null instead.

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.

I agree that returning nullable String looks better when looking at how this is used in other draft PRs. But is there some other reason for this like some components (Card?) already having public Optional<String> getAriaRole() method?

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.

Based on the Card PR, it was done this way to align with HasAriaLabel specifically:

One difference from the API described in the issue is the getter for ARIA role. In the issue, the getter for the ARIA attributes are written as public String getAria...(). However, the already implemented API for ARIA labels in HasAriaLabel return Optional. Therefore, the getter for the new ARIA role attribute also returns Optional in this PR.

Personally I don't have a strong opinion, maybe we could consider making a minor breaking change to the Card API in 25.3 if we want it to return null string instead, it seems not too risky.

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.

Since it's a breaking change, I changed my mind and rather keep it returning Optional just like HasAriaLabel.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I overlooked that part. I agree, let's keep as is then.

@sonarqubecloud

Copy link
Copy Markdown

@tltv
tltv added this pull request to the merge queue Jun 26, 2026
Merged via the queue into main with commit 5118170 Jun 26, 2026
34 checks passed
@tltv
tltv deleted the feat/has-aria-role branch June 26, 2026 11:42
Artur- pushed a commit to vaadin/docs that referenced this pull request Sep 15, 2026
## Summary

Vaadin 25.3 added two accessibility mixin interfaces that the *Mixin
Interfaces* page doesn't list, even though that list is where a reader
looks for what a component can implement:

- `vaadin/flow#24782` — `HasAriaRole` (`setAriaRole()` /
`getAriaRole()`)
- `vaadin/flow#25117`, narrowed by `vaadin/flow#25135` —
`HasAriaDescription` (`setAriaDescribedBy(String)`,
`setAriaDescribedBy(Component)`, `getAriaDescribedBy()`)

## What changed

In `articles/flow/component-internals/mixins.adoc`, under *Other Useful
Mixin Interfaces*:

- added `HasAriaDescription` — the accessible description is set by
referencing existing elements with `setAriaDescribedBy()`, and
supplements the accessible name
- added `HasAriaRole` — sets the `role` attribute on the root element by
default, and the methods can be overridden to target another element
- fixed the name of `HasAriaLabel`, which the same list spelled
`HasArialLabel` (the only occurrence in the docs)

## How to test

Documentation only, no code examples added, so nothing to compile. The
descriptions match the javadoc of `HasAriaRole` and `HasAriaDescription`
in 25.3.

Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com>
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 25.3.0.

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.

5 participants