Skip to content

Commit

Permalink
Improve info panel focusability (fixes #1069) (#1171)
Browse files Browse the repository at this point in the history
* Adds a tabindex to the right info panel's main element so it can be focused regardless of whether it has focus-able content

* check for scrolling before setting/unsetting tabindex and aria label. make elements articles so they'll be readable by screenreaders.
  • Loading branch information
LlGC-jop authored Oct 31, 2024
1 parent c394516 commit 8f8a294
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class MoreInfoDialogue extends Dialogue<
);
this.$content.append(this.$title);

this.$metadata = $('<div class="iiif-metadata-component"></div>');
this.$metadata = $('<article class="iiif-metadata-component"></article>');
this.$content.append(this.$metadata);

this.metadataComponent = new MetadataComponent({
Expand Down Expand Up @@ -98,5 +98,18 @@ export class MoreInfoDialogue extends Dialogue<

resize(): void {
this.setDockedPosition();

// always put tabindex on, so the metadata is focusable,
// just in case there's something wrong with the height
// comparison below
this.$metadata.attr('tabindex', 0);
this.$metadata.attr('aria-label', this.config.content.title);

// if metadata's first group's height is lte than metadata (200px fixed I think),
// there's no scroll happening, so no focus needed, and no aria label either
if(this.$metadata.find('.groups').first().height() <= this.$metadata.height()) {
this.$metadata.removeAttr('tabindex');
this.$metadata.removeAttr('aria-label');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class MoreInfoRightPanel extends RightPanel<MoreInfoRightPanelConfig> {

this.setTitle(this.config.content.title);

this.$metadata = $('<div class="iiif-metadata-component"></div>');
this.$metadata = $('<article class="iiif-metadata-component"></article>');
this.$main.append(this.$metadata);

this.metadataComponent = new MetadataComponent({
Expand Down Expand Up @@ -141,5 +141,18 @@ export class MoreInfoRightPanel extends RightPanel<MoreInfoRightPanelConfig> {
this.$main.height(
this.$element.height() - this.$top.height() - this.$main.verticalMargins()
);

// always put tabindex on, so the main is focusable,
// just in case there's something wrong with the height
// comparison below
this.$main.attr('tabindex', 0);
this.$main.attr('aria-label', this.config.content.title);

// if metadata's height lte main's, no scroll, so no focus needed
// and no aria label either
if(this.$metadata.height() <= this.$main.height()) {
this.$main.removeAttr('tabindex');
this.$main.removeAttr('aria-label');
}
}
}

0 comments on commit 8f8a294

Please sign in to comment.