feat: Bubble ARIA methods#9783
Conversation
| * represent a bubble, or null if the default fallback should be used. See | ||
| * setAriaLabelProvider for more context. | ||
| */ | ||
| export type AriaLabelProvider = (bubble: Bubble) => string | null; |
There was a problem hiding this comment.
I would probably update this to allow either a string or a function that returns a string. Then it will match patterns used elsewhere (in block for the role description, and in input for the aria label). Those two places didn't exist when the design was originally written for this.
There was a problem hiding this comment.
Seems like a good idea. Added.
|
|
||
| const label = this.getAriaLabel()?.trim(); | ||
|
|
||
| aria.setState(element, aria.State.LABEL, label ? label : 'Bubble'); |
There was a problem hiding this comment.
The Bubble string would need to be localized. I do wonder if there's a better default we could use, because "bubble" is so meaningless to end users. But I can't think of another one that's better. At least the built-in use cases of bubble will be able to have better defaults so this would only occur if someone is implementing a custom icon that launches a custom bubble and doesn't bother to set a correct label.
There was a problem hiding this comment.
Good catch, thanks! I agree that it's meaningless, but weighed the trade offs in the same way as you.
* feat: Bubble ARIA methods * fix: lint * fix: code review * fix: whitespace * fix: use standard block * fix: remove unneeded teardown steps
This updates
Bubblewith new API changes:type AriaLabelProviderrecomputeAriaContext()setAriaLabelProvider()getAriaLabel()These new methods ensure that
Bubbles have a valid ARIA label and the default rolegroup. To use,Bubbleowners (such asIcons) are responsible computing the context at the correct times and providing anAriaLabelProviderto override the default"Bubble"label.The basics
The details
Resolves
Fixes #9661
Proposed Changes
Bubble will be updated with new API changes:
The documentation strings explain the contracts of these methods, but it's expected that implementations will never need to override any of these values.
Bubbleowners (such asIcons) are responsible for actually setting up theBubbleinstance's ARIA context to be correct (e.g. by callingrecomputeAriaContextas the correct time). All bubbles are treated as rolegroupunlessrecomputeAriaContextis overridden. The focusable element's label is set to the value returned bygetAriaLabel(or a default'Bubble'if noAriaLabelProvideris configured or it returnsnull, to ensure that at least some human-readable label is used).Reason for Changes
This provides the groundwork that is necessary to give built-in bubble owners (such as mutators, warnings, and comments) reasonable ARIA labels. This will also make it possible for developers to do the same for their own
Bubbleimplementations.Test Coverage
To start, this just tests that the three main types of bubbles we support have the correct role and a label. It also tests, via comments, that a label provider works as expected. A follow-up task will define those providers and test that they are working as expected.
Documentation
Additional Information