Skip to content

Commit

Permalink
Fix: Automated aria-levels bug (fixes #229) (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster authored Sep 6, 2022
1 parent 4c78a59 commit 310c812
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions js/a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ class A11y extends Backbone.Controller {
*/
ariaLevel({
id = null,
level = "1",
level = '1',
override = null
} = {}) {
if (arguments.length === 2) {
// backward compatibility
level = arguments[0];
override = arguments[1];
override = arguments[1];
id = null;
}
// get the global configuration from config.json
Expand All @@ -197,7 +197,7 @@ class A11y extends Backbone.Controller {
* @returns
*/
function calculateLevel(id = null, level, offset = 0) {
const isNumber = !isNaN(level);
const isNumber = !isNaN(level);
const isTypeName = /[a-zA-z]/.test(level);
if (!isTypeName && isNumber) {
// if an absolute value is found, use it, adding the accumulated offset
Expand All @@ -213,7 +213,7 @@ class A11y extends Backbone.Controller {
return calculateLevel(id, nextLevel, offset + relativeDescriptor.offset);
}
// try to find the next relevant ancestor, or use the specified model
const nextModel = data.findById(id)?.findAncestor(relativeDescriptor.type?.toLowerCase()) ?? data.findById(id);
const nextModel = data.findById(id)?.findAncestor(relativeDescriptor.type?.toLowerCase()) ?? data.findById(id);
const nextModelId = nextModel?.get('_id') ?? id;
// check overrides, check title existence, adjust offset accordingly
const hasNextTitle = Boolean(nextModel.get('displayTitle'));
Expand All @@ -223,7 +223,7 @@ class A11y extends Backbone.Controller {
// move towards the parents until an absolute value is found
return calculateLevel(nextModelId, resolvedLevel, accumulatedOffset);
}
return calculateLevel(id, override ?? level)
return calculateLevel(id, override ?? level);
}

/**
Expand Down Expand Up @@ -657,8 +657,8 @@ class A11y extends Backbone.Controller {
// item passed or readable, add to stack before any parent
// siblings
stack.splice(childIndexPosition++, 0, {
item: item,
value: value
item,
value
});
});

Expand Down
2 changes: 1 addition & 1 deletion js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ const helpers = {
level,
override: this._ariaLevel
});
return new Handlebars.SafeString(' role="heading" aria-level="${resolvedLevel}" ');
return new Handlebars.SafeString(` role="heading" aria-level="${resolvedLevel}" `);
},

/**
Expand Down

0 comments on commit 310c812

Please sign in to comment.