Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

fix: support native aria property reflection #6456

Merged
merged 1 commit into from
Nov 10, 2021

Conversation

coryrylan
Copy link
Contributor

@coryrylan coryrylan commented Nov 8, 2021

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • If applicable, have a visual design approval

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • clarity.design website / infrastructure changes
  • Other... Please describe:

What is the current behavior?

The newer aria reflection AP enables elements to set an aria property and have it auto reflect to the attribute.

const element = document.querySelector('div');
element.ariaDisabled = 'true'
<div aria-disabled="true"></div>

This means we do not need the property decorators to handle the reflection on aria* properties and need to adjust the types to match TypeScript in the newer version 4.3.4+. To support the newer versions of TS we need to adjust and remove overrides on any native aria property type. We also need a shim for firefox as it does not fully support aria property reflection yet.
https://wicg.github.io/aom/caniuse.html
https://wicg.github.io/aom/aria-reflection-explainer.html

What is the new behavior?

Components can now use the native aria properties and fallback to a shim for Firefox. This aligns and fixes the mismatched types with TypeScript. See microsoft/TypeScript#46456 for more details

Unblocks part of the Angular 13 update #6455

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@coryrylan coryrylan self-assigned this Nov 8, 2021
ariaExpanded: string | null;
ariaSelected: string | null;
}
}
Copy link
Contributor Author

@coryrylan coryrylan Nov 8, 2021

Choose a reason for hiding this comment

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

This augments some of the aria properties as nullable. TypeScript marks them as string only but this is incorrect and causing issues when trying to set them as null. Once this is fixed in TS we can remove the overloaded Element interface.

This is impacting other Design systems as well
microsoft/TypeScript#46456
microsoft/TypeScript#45047

}
},
});
}
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 is a patch to support the aria property reflection for firefox
https://wicg.github.io/aom/caniuse.html
https://wicg.github.io/aom/aria-reflection-explainer.html

@coryrylan coryrylan force-pushed the topic/core-aria-reflect branch from 07ee3c9 to 085b55d Compare November 8, 2021 18:23
@coryrylan coryrylan requested a review from bdryanovski November 8, 2021 18:23
@@ -101,7 +101,8 @@ export class CdsInternalOverlay extends CdsBaseFocusTrap implements Animatable {
// renderRoot needs delegatesFocus so that focus can cross the shadowDOM
// inside an element with aria-modal set to true
/** @private */
static get shadowRootOptions() {
static get shadowRootOptions(): any {
// any is used until TS 4.4.x adopted through other @cds/* libraries. Can be removed in 6.0
Copy link
Contributor Author

@coryrylan coryrylan Nov 8, 2021

Choose a reason for hiding this comment

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

I set these to any so the 5.x @cds/* libraries continue to work in the older TS verions. Once we branch for 6.x we can remove the any and use the updated types that TS provides.

Copy link
Contributor

Choose a reason for hiding this comment

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

Zero concerns about leaving any here as long as we want.

Copy link
Contributor

@mathisscott mathisscott left a comment

Choose a reason for hiding this comment

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

Question about a barrel import. Beyond that, 👍

@@ -101,7 +101,8 @@ export class CdsInternalOverlay extends CdsBaseFocusTrap implements Animatable {
// renderRoot needs delegatesFocus so that focus can cross the shadowDOM
// inside an element with aria-modal set to true
/** @private */
static get shadowRootOptions() {
static get shadowRootOptions(): any {
// any is used until TS 4.4.x adopted through other @cds/* libraries. Can be removed in 6.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Zero concerns about leaving any here as long as we want.

packages/core/src/internal/index.ts Show resolved Hide resolved
@coryrylan coryrylan force-pushed the topic/core-aria-reflect branch from 83148f8 to 44c6a0e Compare November 8, 2021 20:56
let ariaRegistered = false;

function isNode() {
return (globalThis as any)?.process?.env?.JEST_WORKER_ID !== undefined; // Jest and JSDom breaks on property reflection
Copy link
Contributor Author

Choose a reason for hiding this comment

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

hack: Jest throws since it doesn't seem to support aria properties correctly, once the shim is no longer required for firefox we can delete it

@@ -111,6 +105,11 @@ export class CdsAlertGroup extends LitElement {
`;
}

connectedCallback() {
super.connectedCallback();
this.role = 'region';
Copy link
Contributor

Choose a reason for hiding this comment

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

Other files we are just setting role = 'region' as a property on the class. Why are we doing it in connectedCallback here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had it as a property as you describe but then hit issues with Jest, I can double check to see if the isNode check prevents the issue here

@coryrylan coryrylan force-pushed the topic/core-aria-reflect branch from 44c6a0e to f7febaa Compare November 10, 2021 18:20
@coryrylan coryrylan merged commit a41bcfe into vmware-archive:next Nov 10, 2021
@coryrylan coryrylan mentioned this pull request Nov 11, 2021
14 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants