Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessibility Issue: Focus Not Transferred to AboutModal Dialog on activation #4209

Closed
1 of 3 tasks
bogy0 opened this issue Feb 3, 2024 · 6 comments · Fixed by #5981
Closed
1 of 3 tasks

Accessibility Issue: Focus Not Transferred to AboutModal Dialog on activation #4209

bogy0 opened this issue Feb 3, 2024 · 6 comments · Fixed by #5981
Assignees
Labels
Sev 3 Visible or noticeable to users but does not impede functionality. Has a workaround. type: a11y ♿ Issues not following accessibility standards type: bug 🐛 Something isn't working

Comments

@bogy0
Copy link

bogy0 commented Feb 3, 2024

What package(s) are you using?

  • Carbon for IBM Products (or Carbon for IBM Cloud & Cognitive)
  • Legacy/CDAI
  • Legacy/Security

Detailed description

We have identified an accessibility issue with the <AboutModal /> component. When the modal is triggered to open, the focus remains on the last element that was focused before the modal opened, instead of being transferred to the modal dialog itself. This behavior can cause confusion for keyboard users and is not compliant with WCAG 2.1 success criteria, particularly 2.4.3 Focus Order and 2.4.7 Focus Visible.

Expected Behavior:

When the AboutModal is activated (opened), the focus should automatically move to the modal dialog. Ideally, the focus should be placed on the first interactive element within the dialog, such as a close button or the first link. If no interactive elements are present, the focus should be placed on the container element of the dialog with a tabindex="-1" attribute to ensure it is programmatically focusable.

Current Behavior:

Upon activating the AboutModal, the focus remains on the element that was focused before opening the modal. This behavior forces screen reader users and those relying on keyboard navigation to tab through potentially irrelevant content to reach the modal, undermining the usability and accessibility of the application.

Browser: All

Package: "@carbon/ibm-products": "2.9.0"

Steps to Reproduce:

  1. Navigate to the page with the AboutModal component using a keyboard or screen reader.
  2. Activate the AboutModal button to open the dialog.
  3. Observe that the focus does not move to the open modal dialog, but remains on the previously focused element.

Potential Solution:

Ensure that when the modal opens, focus management is implemented to shift focus to the dialog. This can be achieved by setting the focus programmatically to the dialog's container or the first interactive element within the modal upon opening. Additionally, consider trapping focus within the modal while it is open to improve navigation for keyboard and screen reader users.

@github-project-automation github-project-automation bot moved this to Needs triage 🧐 in Carbon for IBM Products Feb 3, 2024
@elycheea elycheea added needs: ux type: a11y ♿ Issues not following accessibility standards labels Feb 12, 2024
@elycheea
Copy link
Contributor

Are you able to use data-modal-primary-focus?

@sstrubberg
Copy link
Member

Closing for now. Happy to re-open if needed!

@sstrubberg sstrubberg closed this as not planned Won't fix, can't repro, duplicate, stale Apr 1, 2024
@github-project-automation github-project-automation bot moved this from Needs triage 🧐 to Done 🚀 in Carbon for IBM Products Apr 1, 2024
@LiaTsernant
Copy link

LiaTsernant commented May 10, 2024

@elycheea according to AVT the best practice is to move focus on modal's close button. Since the close button is a part of the component, I don't think there's a way for developers to provide data-modal-primary-focus to that element.
I would be happy if there's a way tho. Please let me know if I am missing something.

@sstrubberg Can this issue be reopened since my IBM team is also having a problem with it?
My team has a workaround to move focus but it would be nice if the component had a prop that takes care of it. Similar to Carbon v11's modal selectorPrimaryFocus and launcherButtonRef

Right now our workaround for moving the focus is this snippet:

// Automatically moving focus to the close button when modal opens so users don't need to tab twice
  useEffect(() => {
    if (isOpen) {
      /**
       * setTimeout with no delay ensures that the code will be executed in the next event cycle
       * It prevents race conditions and ensures the close button will always be found when modal opens
       * Carbon uses it for launcherButtonRef: https://github.com/carbon-design-system/carbon/blob/main/packages/react/src/components/Modal/Modal.tsx
       */
      setTimeout(() => {
        const closeButtonFocusSelector = `.${getCarbonClass('modal-close')}`;
        const initialFocusElement = document.querySelector(`#${componentId} ${closeButtonFocusSelector}`);
        if (initialFocusElement) {
          // Cast as HTMLElement since .focus() property does not exist on type 'Element'
          (initialFocusElement as HTMLElement).focus();
        }
      });
    }
  }, [isOpen]);

Thanks for your help!

@sstrubberg sstrubberg reopened this May 10, 2024
@github-project-automation github-project-automation bot moved this from Done 🚀 to Needs triage 🧐 in Carbon for IBM Products May 10, 2024
@elycheea elycheea added type: bug 🐛 Something isn't working Sev 3 Visible or noticeable to users but does not impede functionality. Has a workaround. and removed needs: ux status: needs triage 🕵️‍♀️ status: open question 💬 labels May 13, 2024
@sstrubberg sstrubberg moved this from Needs triage 🧐 to Backlog 🌋 in Carbon for IBM Products May 13, 2024
@makafsal makafsal self-assigned this May 17, 2024
@makafsal makafsal moved this from Backlog 🌋 to In progress in Carbon for IBM Products May 20, 2024
@makafsal
Copy link
Member

@elycheea The AboutModal modal is a passive ComposedModal. This issue seems to be an issue with the Carbon ComposedModal component because, in a passive ComposedModal, it is not focusing on the Close button.

https://react.carbondesignsystem.com/?path=/story/components-composedmodal--passive-modal

@makafsal
Copy link
Member

makafsal commented Jun 4, 2024

@elycheea Raised an issue in Carbon
carbon-design-system/carbon#16650

@makafsal makafsal moved this from Backlog 🌋 to Needs review 👋 in Carbon for IBM Products Aug 30, 2024
@makafsal
Copy link
Member

@elycheea Implemented useFocus() hook in the AboutModal component.

@github-project-automation github-project-automation bot moved this from Needs review 👋 to Done 🚀 in Carbon for IBM Products Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Sev 3 Visible or noticeable to users but does not impede functionality. Has a workaround. type: a11y ♿ Issues not following accessibility standards type: bug 🐛 Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants