Skip to content

Commit aeb5067

Browse files
committed
Fix keyboard explorer to work for all necessary modalities.
1 parent d17d8f0 commit aeb5067

File tree

5 files changed

+39
-14
lines changed

5 files changed

+39
-14
lines changed

ts/a11y/explorer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,12 @@ export function ExplorerMathDocumentMixin<B extends MathDocumentConstructor<HTML
257257
* @return {ExplorerMathDocument} The MathDocument (so calls can be chained)
258258
*/
259259
public explorable(): ExplorerMathDocument {
260-
this.options.enableSpeech = true;
260+
if (this.options.a11y.speech) {
261+
this.options.enableSpeech = true;
262+
}
263+
if (this.options.a11y.braille) {
264+
this.options.enableBraille = true;
265+
}
261266
if (!this.processed.isSet('explorer')) {
262267
if (this.options.enableExplorer) {
263268
if (!this.explorerRegions) {

ts/a11y/explorer/ExplorerPool.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,19 +204,31 @@ export class ExplorerPool {
204204
this.attach();
205205
}
206206

207+
/**
208+
* A11y options keys associated with the speech explorer.
209+
*/
210+
private speechExplorerKeys = ['speech', 'braille', 'keyMagnifier'];
211+
207212
/**
208213
* Attaches the explorers that are currently meant to be active given
209214
* the document options. Detaches all others.
210215
*/
211216
public attach() {
212217
this.attached = [];
213218
let keyExplorers = [];
214-
for (let key of Object.keys(this.explorers)) {
215-
let explorer = this.explorers[key];
219+
for (let [key, explorer] of Object.entries(this.explorers)) {
216220
if (explorer instanceof SpeechExplorer) {
217221
explorer.AddEvents();
218222
explorer.stoppable = false;
219223
keyExplorers.unshift(explorer);
224+
if (this.speechExplorerKeys.some(
225+
exKey => this.document.options.a11y[exKey])) {
226+
explorer.Attach();
227+
this.attached.push(key);
228+
} else {
229+
explorer.Detach();
230+
}
231+
continue;
220232
}
221233
if (this.document.options.a11y[key]) {
222234
explorer.Attach();

ts/a11y/explorer/KeyExplorer.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export class SpeechExplorer extends AbstractExplorer<string> implements KeyExplo
178178
const prev = this.node.querySelector(prevNav);
179179
if (prev) {
180180
prev.removeAttribute('tabindex');
181+
this.FocusOut(null);
181182
}
182183
this.current = clicked;
183184
if (!this.triggerLinkMouse()) {
@@ -486,11 +487,13 @@ export class SpeechExplorer extends AbstractExplorer<string> implements KeyExplo
486487
this.current.setAttribute('tabindex', '0');
487488
this.current.focus();
488489
super.Start();
489-
if (this.document.options.a11y.subtitles) {
490+
if (this.document.options.a11y.speech &&
491+
this.document.options.a11y.subtitles) {
490492
promise.then(
491493
() => this.region.Show(this.node, this.highlighter));
492494
}
493-
if (this.document.options.a11y.viewBraille) {
495+
if (this.document.options.a11y.braille &&
496+
this.document.options.a11y.viewBraille) {
494497
promise.then(
495498
() => this.brailleRegion.Show(this.node, this.highlighter));
496499
}
@@ -645,7 +648,8 @@ export class SpeechExplorer extends AbstractExplorer<string> implements KeyExplo
645648
public semanticFocus() {
646649
const node = this.current || this.node;
647650
const id = node.getAttribute('data-semantic-id');
648-
const stree = this.generators.speechGenerator.getRebuilt().stree;
651+
const stree = this.generators.speechGenerator.getRebuilt()?.stree;
652+
if (!stree) return null;
649653
const snode = stree.root.querySelectorAll((x: any) => x.id.toString() === id)[0];
650654
return snode || stree.root;
651655
}

ts/a11y/semantic-enrich.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,10 @@ export function EnrichedMathItemMixin<N, T, D, B extends Constructor<AbstractMat
263263
if (!speech && !braille) return;
264264
const adaptor = document.adaptor;
265265
const node = this.typesetRoot;
266-
if (speech) {
266+
if (speech && document.options.enableSpeech) {
267267
adaptor.setAttribute(node, 'aria-label', speech as string);
268268
}
269-
if (braille) {
269+
if (braille && document.options.enableBraille) {
270270
adaptor.setAttribute(node, 'aria-braillelabel', braille as string);
271271
}
272272
for (const child of adaptor.childNodes(node) as N[]) {

ts/a11y/speech/GeneratorPool.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,17 @@ export class GeneratorPool<N, T, D> {
370370
this.dummyList.forEach(attr => this.copyAttributes(xml, node, attr));
371371
}
372372
}
373-
const speech = this.getLabel(node);
374-
if (speech) {
375-
this.adaptor.setAttribute(node, 'aria-label', buildSpeech(speech, locale)[0]);
373+
if (this.options.a11y.speech) {
374+
const speech = this.getLabel(node);
375+
if (speech) {
376+
this.adaptor.setAttribute(node, 'aria-label', buildSpeech(speech, locale)[0]);
377+
}
376378
}
377-
const braille = this.adaptor.getAttribute(node, 'data-semantic-braille');
378-
if (braille) {
379-
this.adaptor.setAttribute(node, 'aria-braillelabel', braille);
379+
if (this.options.a11y.braille) {
380+
const braille = this.adaptor.getAttribute(node, 'data-semantic-braille');
381+
if (braille) {
382+
this.adaptor.setAttribute(node, 'aria-braillelabel', braille);
383+
}
380384
}
381385
const xmlChildren = Array.from(xml.childNodes);
382386
Array.from(this.adaptor.childNodes(node)).forEach(

0 commit comments

Comments
 (0)