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

AG-12606 Screenreader fixes #2479

Merged
merged 6 commits into from
Sep 13, 2024
Merged

AG-12606 Screenreader fixes #2479

merged 6 commits into from
Sep 13, 2024

Conversation

olegat
Copy link
Contributor

@olegat olegat commented Sep 12, 2024

@olegat olegat marked this pull request as ready for review September 12, 2024 13:55
@olegat olegat requested review from alantreadway and a team as code owners September 12, 2024 13:55
// menu item without an accessible text alternative.
type LabelAndIcon = { label: string; icon?: AgIconName; altText?: undefined };
type IconOnly = { label?: undefined; icon: AgIconName; altText: string };
export type LabelIcon = LabelAndIcon | IconOnly;
Copy link
Contributor Author

@olegat olegat Sep 12, 2024

Choose a reason for hiding this comment

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

Note: This LabelIcon allows 3 syntax modes:

{ label }         // text only
{ label, icon }   // text & icon
{ icon, altText } // icon only (with altText for screenreaders)

Specifying an icon without altText, or specifying both a label and altText will raise a compiler error.

if (key === 'ariaControls') return 'aria-controls';
return key;
// Convert camelCaseString to kebab-case-string
return key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This won't work for some property-attribute pairs like ariaSetSize / aria-setsize or ariaPosInSet / aria-posinset. We might want to have a more strict interface for the Attrs type.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, the current Attrs type also allows function properties like setEventListener which is a bit leaky.

If we only care about targetting aria attributes, could we just replace the aria with aria- and not kebab the whole thing? Or are there other attrs we need to consider?

The reason I called it "missing" aria attrs is the typescript types for elements includes many attrs like ariaLabel but not ariaControls. Not sure if that is just our ts version being out of date or if it implies something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AG-Grid uses wrappers to set aria attributes:
https://github.com/ag-grid/ag-grid/blob/419770ca302ce87bc3c9a64b51a464c86132ab7c/community-modules/core/src/utils/aria.ts

We have something similar but it's not so widely used unfortunately:
https://github.com/ag-grid/ag-charts/blob/c2f6bb944c7dd8bce14803cdac6717a485e2537f/packages/ag-charts-community/src/util/attributeUtil.ts

It might be a good idea to start using attributeUtil.ts in more places sure as here.

@@ -67,6 +67,8 @@ export const AG_CHARTS_LOCALE_EN_US: Record<string, string> = {
iconAltTextAlignCenter: 'Center',
// Alt-text for the 'position-right' icon
iconAltTextAlignRight: 'Right',
// Alt-text for the 'close' icon
iconAltTextClose: 'Close',
Copy link
Member

Choose a reason for hiding this comment

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

Worth highlighting this with @JamesSwinton - #2478

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted. Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

We'll hold off merging #2478 until these new keys are merged.

Copy link
Member

@alantreadway alantreadway left a comment

Choose a reason for hiding this comment

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

LGTM

The :focus-visible CSS pseudo-class will take care of showing/hidden the
indicator box.
The camelCase to kebab-case conversion elements.ts will not correctly work
for property/attribute pairs like ariaSetSize/aria-setsize.

Also, the current type mechanism exposes "attributes" like addEventListener
which is a method not an attribute.

Piggy-back on the existing `setAttribute` function to enforce type safety.
@olegat olegat merged commit 480143b into latest Sep 13, 2024
26 checks passed
@olegat olegat deleted the AG-12606/screenreader_fixes branch September 13, 2024 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants