Skip to content

Commit

Permalink
feat(d.ts): add types for more utils and commons functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hamax committed Jul 18, 2023
1 parent a35a870 commit dcc9dd3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
37 changes: 37 additions & 0 deletions axe.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,42 @@ declare namespace axe {
shadowSelect: (selector: CrossTreeSelector) => Element | null;
shadowSelectAll: (selector: CrossTreeSelector) => Element[];
getStandards(): Required<Standards>;
DqElement: new (
elm: Element,
options?: { absolutePaths?: boolean }
) => SerialDqElement;
uuid: (
options?: { random?: Uint8Array | Array<number> },
buf?: Uint8Array | Array<number>,
offset?: number
) => string | Uint8Array | Array<number>;
}

interface Aria {
getRoleType: (role: string | Element | VirtualNode | null) => string | null;
}

interface Dom {
isFocusable: (node: Element | VirtualNode) => boolean;
isNativelyFocusable: (node: Element | VirtualNode) => boolean;
}

type AccessibleTextOptions = {
inControlContext?: boolean;
inLabelledByContext?: boolean;
};

interface Text {
accessibleText: (
element: Element,
options?: AccessibleTextOptions
) => string;
}

interface Commons {
aria: Aria;
dom: Dom;
text: Text;
}

interface EnvironmentData {
Expand All @@ -405,6 +441,7 @@ declare namespace axe {
let version: string;
let plugins: any;
let utils: Utils;
let commons: Commons;

/**
* Source string to use as an injected script in Selenium
Expand Down
11 changes: 11 additions & 0 deletions typings/axe-core/axe-core-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,14 @@ var pluginSrc: axe.AxePlugin = {
};
axe.registerPlugin(pluginSrc);
axe.cleanup();

// Utils
const dqElement = new axe.utils.DqElement(document.body);
const element = axe.utils.shadowSelect(dqElement.selector[0]);
const uuid = axe.utils.uuid() as string;

// Commons
axe.commons.aria.getRoleType('img');
axe.commons.dom.isFocusable(document.body);
axe.commons.dom.isNativelyFocusable(document.body);
axe.commons.text.accessibleText(document.body);

0 comments on commit dcc9dd3

Please sign in to comment.