From 76529a17babce4fcd341e5a15b7779cdd2373a69 Mon Sep 17 00:00:00 2001 From: Bruce B Date: Mon, 24 Jan 2022 09:45:01 -0800 Subject: [PATCH] feat(client): JAWS 2022 bugfix for monaco editor (#44784) * feat: JAWS 2021 bugfix for monaco editor * update menu label and toggle announcement * Update client/src/templates/Challenges/classic/editor.tsx Co-authored-by: Oliver Eyton-Williams * Update client/src/templates/Challenges/classic/editor.tsx Co-authored-by: Oliver Eyton-Williams * Update client/src/templates/Challenges/classic/editor.tsx Co-authored-by: Oliver Eyton-Williams * clarify visibility hack for live region * Update client/src/templates/Challenges/classic/editor.tsx Co-authored-by: Shaun Hamilton Co-authored-by: Oliver Eyton-Williams Co-authored-by: Shaun Hamilton --- .../templates/Challenges/classic/editor.tsx | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/client/src/templates/Challenges/classic/editor.tsx b/client/src/templates/Challenges/classic/editor.tsx index 820984df5f..8e479f1c81 100644 --- a/client/src/templates/Challenges/classic/editor.tsx +++ b/client/src/templates/Challenges/classic/editor.tsx @@ -409,7 +409,63 @@ const Editor = (props: EditorProps): JSX.Element => { }); } }); + // Introduced as a work around for a bug in JAWS 2022 + // https://github.com/FreedomScientific/VFO-standards-support/issues/598 + editor.addAction({ + id: 'toggle-aria-roledescription', + label: 'Toggle aria-roledescription', + keybindings: [ + monaco.KeyMod.CtrlCmd | monaco.KeyMod.Alt | monaco.KeyCode.KEY_J + ], + run: toggleAriaRoledescription + }); editor.onDidFocusEditorWidget(() => props.setEditorFocusability(true)); + + // aria-roledescription is on (true) by default, check if it needs + // to be removed. + if (!getStoredAriaRoledescription()) { + setAriaRoledescription(false); + } + }; + + const toggleAriaRoledescription = () => { + const newRoledescription = !getStoredAriaRoledescription(); + setAriaRoledescription(newRoledescription); + ariaAlert( + `aria-roledescription has been turned ${ + newRoledescription ? 'on' : 'off' + }` + ); + }; + + const setAriaRoledescription = (value: boolean) => { + const textareas = document.querySelectorAll('.monaco-editor textarea'); + textareas.forEach(textarea => { + value + ? textarea.setAttribute('aria-roledescription', 'editor') + : textarea.removeAttribute('aria-roledescription'); + }); + store.set('ariaRoledescription', value); + }; + + const getStoredAriaRoledescription = () => + !!(store.get('ariaRoledescription') ?? true); + + // Borrowed from + // freeCodeCamp/node_modules/monaco-editor/esm/vs/base/browser/ui/aria/aria.js + // Uses the aria live region provided by monaco. + const ariaAlert = (message: string) => { + const ariaLive: NodeListOf = + document.querySelectorAll('.monaco-alert'); + if (ariaLive.length > 0) { + const liveText = ariaLive[0]; + liveText.textContent = message; + // Hack used by monaco to force older browsers to announce the update to + // the live region. + // See https://www.tpgi.com/html5-accessibility-chops-aria-rolealert-browser-support/ + liveText.style.visibility = 'hidden'; + liveText.style.visibility = 'visible'; + } }; const descriptionZoneCallback = (