Repository navigation
feat: add HasAriaRole interface - #24782
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Are there use cases where you implement |
Most of field components implement |
| * @return an optional ARIA role of the component if no ARIA role has been | ||
| * set | ||
| */ | ||
| default Optional<String> getAriaRole() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Since it's a breaking change, I changed my mind and rather keep it returning Optional just like HasAriaLabel.
There was a problem hiding this comment.
I overlooked that part. I agree, let's keep as is then.
|
## 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>
|
This ticket/PR has been released with Vaadin 25.3.0. |



Added a shared
HasAriaRolemixin 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
HasAriaLabelincom.vaadin.flow.componentand follows the same pattern: attribute-based storage,nullclears the attribute, and the getter returns anOptional.Part of vaadin/flow-components#9489
🤖 Generated with Claude Code