adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
12.93k stars 1.12k forks source link

Accessibilty issue when Monaco Editor is in a Spectrum Dialog #6774

Open gayane-1 opened 3 months ago

gayane-1 commented 3 months ago

Provide a general summary of the issue here

We are currently using the Monaco Editor in a Spectrum Dialog and have encountered an accessibility issue. When using the tab toggle functionality (pressing ctrl+m (Windows) or ctrl+shift+m(Mac)) to switch between spaces and the next focusable element, the screen reader does not provide alerts about that when the Editor is inside a DialogContainer. However, it works correctly outside of the DialogContainer.

๐Ÿค” Expected Behavior?

Screen readers should alert users like this: "Pressing tab will now insert a tab character/focus on the next focusable element."

๐Ÿ˜ฏ Current Behavior

The screen reader does not provide alerts about that when the Editor is inside a DialogContainer.

๐Ÿ’ Possible Solution

In our case monaco-aria-container being aria-hidden when the dialog opens is the cause.

๐Ÿ”ฆ Context

No response

๐Ÿ–ฅ๏ธ Steps to Reproduce

Problem: When inside the editor area, pressing ctrl+m (Windows) or ctrl+shift+m(Mac) changes the tab functionality to either insert spaces or move to the next focusable element. Screen readers should alert users by saying something like this: "Pressing tab will now insert a tab character/focus on the next focusable element.", however this alert is not occurring when the editor (in code: Calculation component) is inside the dialog.

Please check out App.tsx and the comments. There is:

Feel free to switch between those and test accordingly.

  1. In UI, click on the light-aquamarine-bordered area to activate the input field, that is our Editor.
  2. Turn on the screen reader for accessibility testing.
  3. Press Tab and use Ctrl+Shift+M (Mac) to toggle between inserting spaces or moving to the next focusable element.

Note:

Draft prototype in CodeSandbox

Version

3.30.0

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

MacOS

๐Ÿงข Your Company/Team

No response

๐Ÿ•ท Tracking Issue

No response

majornista commented 3 months ago

In React-Aria, we use the [data-live-announcer] or [data-react-aria-top-layer] attribute to identify elements that should not be hidden from the accessibility tree when ariaHideOutside executes.

I was able to fix the CodeSandbox example you shared by adding the following to the useLayoutEffect callback method within MonacoEditorReact at line 89:

      const ariaContainer = document.querySelector(".monaco-aria-container");
      if (ariaContainer) {
        ariaContainer.dataset.liveAnnouncer = true;
      }
snowystinger commented 3 months ago

@majornista First, thanks for the workaround.

We should discuss possible API's to make this easier. I'm still worried that there may be other cases where this isn't as easy. I think it'd be good to be able to register other live announcer regions for the ariaHideOutside to avoid/omit.