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

A11y aria labels computation #355

Merged
merged 2 commits into from
Sep 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 24 additions & 3 deletions ts/a11y/semantic-enrich.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ export function EnrichedMathItemMixin<N, T, D, B extends Constructor<AbstractMat
/**
* @param {MathDocument} document The MathDocument for the MathItem
*/
attachSpeech(document: MathDocument<N, T, D>) {
public attachSpeech(document: MathDocument<N, T, D>) {
if (this.state() >= STATE.ATTACHSPEECH) return;
const attributes =this.root.attributes;
const speech = (attributes.get('aria-label') || attributes.get('data-semantic-speech')) as string;
const attributes = this.root.attributes;
const speech = (attributes.get('aria-label') ||
this.getSpeech(this.root)) as string;
if (speech) {
const adaptor = document.adaptor;
const node = this.typesetRoot;
Expand All @@ -146,6 +147,26 @@ export function EnrichedMathItemMixin<N, T, D, B extends Constructor<AbstractMat
this.state(STATE.ATTACHSPEECH);
}

/**
* Retrieves the actual speech element that should be used as aria label.
* @param {MmlNode} node The root node to search from.
* @return {string} The speech content.
*/
private getSpeech(node: MmlNode): string {
const attributes = node.attributes;
if (!attributes) return;
const speech = attributes.getExplicit('data-semantic-speech') as string;
if (!attributes.getExplicit('data-semantic-parent') && speech) {
return speech;
}
for (let child of node.childNodes) {
let value = this.getSpeech(child as MmlNode);
if (value != null) {
return value;
}
}
}

};

}
Expand Down