Skip to content

Commit

Permalink
Make accessible click function work with both space and enter, with o…
Browse files Browse the repository at this point in the history
…ptions for anchor behaviour
  • Loading branch information
LlGC-jop committed Oct 22, 2024
1 parent e5e3b16 commit 581f405
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ export class ContentLeftPanel extends LeftPanel<ContentLeftPanelConfig> {

this.onAccessibleClick(this.$treeButton, () => {
this.openTreeView();
});
}, true, true);

this.onAccessibleClick(this.$thumbsButton, () => {
this.openThumbsView();
});
}, true, true);

this.setTitle(this.content.title);

Expand Down
18 changes: 15 additions & 3 deletions src/content-handlers/iiif/modules/uv-shared-module/Panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,30 @@ export class Panel {
onAccessibleClick(
el: JQuery,
callback: (e: JQueryEventObject) => void,
withClick = true
withClick = true,
anchorAsButton = false
) {

if (withClick) {
el.on("click", (e) => {
callback(e);
});
}
el.on("keyup", (e) => {
if (e.keyCode === 32) {

el.on("keydown", (e) => {

// by passing anchorAsButton as true this will become false
// and so an anchor won't be excluded from Space presses
let isAnchor = e.target.nodeName === 'A' && !anchorAsButton;

// 13 = Enter, 32 = Space
if ((e.which === 32 && !isAnchor) || e.which === 13) {
// stops space scrolling the page
e.preventDefault();
callback(e);
}
});

}

resize(): void {
Expand Down

0 comments on commit 581f405

Please sign in to comment.