Skip to content

Commit

Permalink
Triggering links from the explorer in CHTML.
Browse files Browse the repository at this point in the history
  • Loading branch information
zorkow committed Apr 21, 2021
1 parent 0b51a5f commit d492e26
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions ts/a11y/explorer/KeyExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export class SpeechExplorer extends AbstractKeyExplorer<string> {
}
if (this.active) {
this.Move(code);
if (this.triggerLink(code)) return;
this.stopEvent(event);
return;
}
Expand All @@ -301,6 +302,24 @@ export class SpeechExplorer extends AbstractKeyExplorer<string> {
}
}

/**
* Programmatically triggers a link if the focused node contains one.
*/
protected triggerLink(code: number) {
if (code !== 13) {
return false;
}
let node = this.walker.getFocus().getNodes()?.[0];
let focus = node?.
getAttribute('data-semantic-postfix')?.
match(/(^| )link($| )/);
if (focus) {
// Works for CHTML only.
node.parentElement.click();
return true;
}
return false;
}

/**
* @override
Expand Down
2 changes: 1 addition & 1 deletion ts/a11y/sre_browser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ declare namespace sre {
}

interface Focus {
getNodes(): Node[];
getNodes(): Element[];
}

interface Walker {
Expand Down

0 comments on commit d492e26

Please sign in to comment.