Skip to content

Commit

Permalink
Accessibility fixes for report.html and dismiss tooltip when clicked (#…
Browse files Browse the repository at this point in the history
…200)

* Remove unneeded attributes, fix bug where tooltip cannot be dismissed when clicked

* Fix regex expression for safari browser

---------

Co-authored-by: jodichoo <[email protected]>
  • Loading branch information
jodichoo and jodichoo authored Oct 19, 2023
1 parent b8c5368 commit f07d712
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
6 changes: 1 addition & 5 deletions static/ejs/partials/scripts/ruleOffcanvas.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ category summary is clicked %>
document.getElementById('expandedRuleConformance').replaceChildren(
createElementFromString(`
<div class="d-flex align-items-center">
<div role="group" ${
selectedRule.conformance[0] === 'best-practice'
? 'aria-hidden="true"'
: `aria-label="${conformanceLevels[selectedRule.conformance[0]]}"`
} class="conformance-bubble ${selectedRule.conformance[0]}"></div>
<div aria-hidden="true" class="conformance-bubble ${selectedRule.conformance[0]}"></div>
${
selectedRule.conformance[0] === 'best-practice'
? `<span>Best practice</span>`
Expand Down
9 changes: 3 additions & 6 deletions static/ejs/partials/scripts/utils.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
const purpleAiHtmlETL = <%- purpleAi.htmlETL %>;
const purpleAiRules = <%- JSON.stringify(purpleAi.rules) %>;
const htmlTagAndAttributeRegex = new RegExp(
/((?<=[<])\s*([a-zA-Z][^\s>/]*)\b)|([\w-]+)\s*(?==\s*["']([^"']*)["'])/g,
);
const htmlTagAndAttributeRegex = new RegExp(/([a-zA-Z][^\s/>]*\b)|([\w-]+)\s*=\s*["']([^"']*)["']/g);
const rulesUsingRoles = [
'aria-allowed-attr',
Expand All @@ -23,9 +21,8 @@
];
const createLabelForRuleWithRole = html => {
const htmlTagAndRoleAttributeRegex = new RegExp(
/(?<=<)\s*([a-zA-Z][^\s>/]*\b)|role="([^"]*)"/g,
);
const htmlTagAndRoleAttributeRegex = new RegExp(/<\s*([a-zA-Z][^\s/>]*\b)|role="([^"]*)"/g);
const htmlLabel = html.match(htmlTagAndRoleAttributeRegex).toString().replaceAll(',', '_');
return htmlLabel || '';
Expand Down
4 changes: 3 additions & 1 deletion static/ejs/report.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
document.querySelectorAll('[data-bs-toggle="tooltip"]'),
);
tooltipTriggerList.map((tooltipTriggerEl) => {
return new bootstrap.Tooltip(tooltipTriggerEl);
const tooltip = new bootstrap.Tooltip(tooltipTriggerEl);
tooltipTriggerEl.addEventListener('mouseleave', () => tooltip.hide());
return tooltip;
});
};
document.addEventListener('DOMContentLoaded', initTooltips);
Expand Down
4 changes: 3 additions & 1 deletion static/ejs/summary.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
document.querySelectorAll('[data-bs-toggle="tooltip"]'),
);
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl);
const tooltip = new bootstrap.Tooltip(tooltipTriggerEl);
tooltipTriggerEl.addEventListener('mouseleave', () => tooltip.hide());
return tooltip;
});
});
</script>
Expand Down

0 comments on commit f07d712

Please sign in to comment.