Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changeset/two-moose-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@patternfly/pfe-core": patch
---
`InternalsController`: allows accessibility auditing tools to access element internals.
18 changes: 12 additions & 6 deletions core/pfe-core/controllers/internals-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ import {
type ReactiveControllerHost,
} from 'lit';

function isARIAMixinProp(key: string): key is keyof ARIAMixin {
return key === 'role' || key.startsWith('aria');
}

type FACE = HTMLElement & {
formDisabledCallback?(disabled: boolean): void;
};

interface InternalsControllerOptions extends Partial<ARIAMixin> {
getHTMLElement?(): HTMLElement;
}

const protos = new WeakMap();

let constructingAllowed = false;

interface InternalsControllerOptions extends Partial<ARIAMixin> {
getHTMLElement?(): HTMLElement;
globalThis._elementInternals ??= new WeakMap<Element, ElementInternals>();

function isARIAMixinProp(key: string): key is keyof ARIAMixin {
return key === 'role' || key.startsWith('aria');
}

/**
Expand Down Expand Up @@ -263,6 +265,8 @@ export class InternalsController implements ReactiveController, ARIAMixin {
this.initializeOptions(options);
InternalsController.instances.set(host, this);
this.#polyfillDisabledPseudo();
// Expose internals to aXe Core
globalThis._elementInternals.set(this.host, this.internals);
}

/**
Expand Down Expand Up @@ -335,6 +339,8 @@ export class InternalsController implements ReactiveController, ARIAMixin {

/** @see https://w3c.github.io/aria/#ref-for-dom-ariamixin-ariaactivedescendantelement-1 */
declare global {
// https://github.com/webcomponents-cg/community-protocols/pull/75
var _elementInternals: WeakMap<Element, ElementInternals>; // eslint-disable-line no-var
interface ARIAMixin {
ariaActiveDescendantElement: Element | null;
ariaControlsElements: readonly Element[] | null;
Expand Down
Loading