DEV Community

Cover image for Accessibility Breakdown | Dynamic Content
Ashley Smith for Developers @ Asurion

Posted on • Updated on

Accessibility Breakdown | Dynamic Content

Todays mini series of things you can do right now covers checking and fixing dynamic content to make them more accessible. Let's get into it:

alert icon

Why it Matters:

  • Accessibility Impact: Dynamic content alerts play a vital role in ensuring that users with disabilities, particularly those using assistive technologies like screen readers, are aware of important changes or updates on a web page.
  • User Experience: These alerts improve user engagement by providing timely information, enhancing the overall user experience.

Quick Check:

  • Manual Inspection: Begin by manually reviewing your application for dynamic content alerts. Look for notifications, messages, or updates that appear or change dynamically. The example below shows an alert that dynamically appears after a user clicks a link.

Image description

  • Automated Testing: Utilize accessibility testing tools such as Axe or WAVE to identify any dynamic content alerts that may be missing accessible labels or attributes.

  • Screen Reader Testing: Test your application using a screen reader to experience how dynamic content alerts are conveyed to users who rely on auditory feedback. If you close your eyes and you don't understand there was a content change or alert you'll need to add a fix.


Quick Fixes:

  • Use ARIA Roles and Attributes: Ensure dynamic content alerts are properly marked up using Accessible Rich Internet Applications (ARIA) roles and attributes. For example, use role="alert" on error messages or when a form is submitted to convey urgent notifications indicating to screen readers that it is important and should be announced immediately.
<!-- Dynamic content alert without proper ARIA markup -->
<div class="alert">
  Error: Please enter a valid email address.
</div>

<!-- Dynamic content alert with proper ARIA markup -->
<div class="alert" role="alert" aria-live="assertive">
  Error: Please enter a valid email address.
</div>

Enter fullscreen mode Exit fullscreen mode
  • Focus Management: Implement focus management to ensure that screen readers announce newly appeared content to users and focus is appropriately set to the updated element. This can be achieved by adding a tabindex attribute with a value of -1 to make the element focusable, and then calling something like a focus() method on it. This simple step ensures that screen reader users are alerted to the presence of new content.
  • Keyboard Accessibility: Ensure users can dismiss or interact with dynamic alerts using keyboard controls alone, without relying on mouse input if needed.

Dismiss Icon


Testing:

  • Thoroughly test your application post-fix to ensure all dynamic content alerts are properly announced, understood, and accessible to users.
  • Consider writing an Axe test using aria rules to ensure the proper attributes exist.
describe('Accessibility tests', () => {
  test('Dynamic content alerts have proper ARIA attributes', async () => {
    const { container } = render(<YourComponentWithDynamicAlerts />); // Replace with your component
    const axeConfig = {
      rules: {
        'aria-roles': { enabled: true },
        'aria-allowed-attr': { enabled: true }
      }
    };
    const results = await axe(container, axeConfig);
    expect(results).toHaveNoViolations();
  });
});
Enter fullscreen mode Exit fullscreen mode

By following these quick steps, you can quickly enhance the accessibility of dynamic content in your application, contributing to a more inclusive online environment for all users. Accessibility is an ongoing journey, so start making a positive impact today! 🌟


Helpful links
Free A11y tools:

A11y Info:

Top comments (0)