Skip to content

Commit d492e26

Browse files
committed
Triggering links from the explorer in CHTML.
1 parent 0b51a5f commit d492e26

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

ts/a11y/explorer/KeyExplorer.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ export class SpeechExplorer extends AbstractKeyExplorer<string> {
292292
}
293293
if (this.active) {
294294
this.Move(code);
295+
if (this.triggerLink(code)) return;
295296
this.stopEvent(event);
296297
return;
297298
}
@@ -301,6 +302,24 @@ export class SpeechExplorer extends AbstractKeyExplorer<string> {
301302
}
302303
}
303304

305+
/**
306+
* Programmatically triggers a link if the focused node contains one.
307+
*/
308+
protected triggerLink(code: number) {
309+
if (code !== 13) {
310+
return false;
311+
}
312+
let node = this.walker.getFocus().getNodes()?.[0];
313+
let focus = node?.
314+
getAttribute('data-semantic-postfix')?.
315+
match(/(^| )link($| )/);
316+
if (focus) {
317+
// Works for CHTML only.
318+
node.parentElement.click();
319+
return true;
320+
}
321+
return false;
322+
}
304323

305324
/**
306325
* @override

ts/a11y/sre_browser.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ declare namespace sre {
2121
}
2222

2323
interface Focus {
24-
getNodes(): Node[];
24+
getNodes(): Element[];
2525
}
2626

2727
interface Walker {

0 commit comments

Comments
 (0)