diff --git a/components/lib/toggle-annotations.ts b/components/lib/toggle-annotations.ts index fa219a7a62..f74007f0b0 100644 --- a/components/lib/toggle-annotations.ts +++ b/components/lib/toggle-annotations.ts @@ -21,6 +21,22 @@ export default function toggleAnnotation() { const annotationButtons = Array.from(document.querySelectorAll('div.BtnGroup button')) if (!annotationButtons.length) return + if (!document.getElementById('tooltip-inline')) { + const theSpan = document.createElement('span') + theSpan.id = 'tooltip-inline' + theSpan.classList.add('visually-hidden') + theSpan.innerText = 'Render annotations inline with the code sample.' + document.body.appendChild(theSpan) + } + + if (!document.getElementById('tooltip-beside')) { + const theSpan = document.createElement('span') + theSpan.id = 'tooltip-beside' + theSpan.classList.add('visually-hidden') + theSpan.innerText = 'Render annotations beside the code sample.' + document.body.appendChild(theSpan) + } + const cookie = validateMode(Cookies.get('annotate-mode')) // will default to beside displayAnnotationMode(annotationButtons, cookie) @@ -46,9 +62,13 @@ function setActive(annotationButtons: Array, targetMode?: string) { targetMode = validateMode(targetMode) annotationButtons.forEach((el) => { if (el.getAttribute('value') === targetMode) { - el.ariaSelected = 'true' + el.ariaCurrent = 'true' + el.classList.add('selected') activeElements.push(el) - } else el.removeAttribute('aria-selected') + } else { + el.removeAttribute('aria-current') + el.classList.remove('selected') + } }) if (!activeElements.length) diff --git a/src/content-render/unified/annotate.js b/src/content-render/unified/annotate.js index db242ff9bf..01d1191f2c 100644 --- a/src/content-render/unified/annotate.js +++ b/src/content-render/unified/annotate.js @@ -134,8 +134,8 @@ function getSubnav() { name: 'annotate-display', value: 'beside', type: 'button', - ariaLabel: 'Display annotations beside the code sample', - className: 'BtnGroup-item btn btn-sm tooltipped tooltipped-nw', + className: 'BtnGroup-item btn btn-sm', + ariaDescribedBy: 'tooltip-beside', }, ['Beside'], ) @@ -145,8 +145,8 @@ function getSubnav() { name: 'annotate-display', value: 'inline', type: 'button', - ariaLabel: 'Display annotations inline as comments of the code sample', - className: 'BtnGroup-item btn btn-sm tooltipped tooltipped-nw', + className: 'BtnGroup-item btn btn-sm', + ariaDescribedBy: 'tooltip-inline', }, ['Inline'], ) diff --git a/tests/rendering/__snapshots__/annotate.js.snap b/tests/rendering/__snapshots__/annotate.js.snap index 58672d1766..2a3ed52ef7 100644 --- a/tests/rendering/__snapshots__/annotate.js.snap +++ b/tests/rendering/__snapshots__/annotate.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`annotate renders annotations 1`] = ` -"
YAML