Accessibility Breakdown | Dynamic Content
Tags: a11y, webdev, webaccessibility, inclusion
Published: 2024-05-22 16:00:00

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ul9iu508998vhjz4sk2z.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7law17zic533kgn7vxxh.png)


- **Automated Testing**: Utilize accessibility testing tools such as [Axe](https://chromewebstore.google.com/detail/axe-devtools-web-accessib/lhdoppojpmngadmnindnejefpokejbdd?utm_source=deque.com&utm_medium=referral&utm_campaign=axe_hero) or [WAVE](https://chromewebstore.google.com/detail/wave-evaluation-tool/jbbplnpkjmmeebjpijfedlgcdilocofh) 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.

```html
<!-- 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>

```
- **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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9o31fnrhqzceysnr5wr8.png)

---

## 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. 

```react
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();
  });
});
```

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:

- [NVDA Screen Reader
](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwj7uqDNm_D6AhUiEFkFHfvrB9QQFnoECBYQAQ&url=https%3A%2F%2Fwww.nvaccess.org%2Fdownload%2F&usg=AOvVaw3AAc5nrFrg0lylpULGjjxr)
- [Axe DevTools Chrome Extension](https://chromewebstore.google.com/detail/axe-devtools-web-accessib/lhdoppojpmngadmnindnejefpokejbdd)
- [WAVE Browser Chrome Extension
](https://wave.webaim.org/extension/)
- [Web Developer Chrome Extension](https://chromewebstore.google.com/detail/web-developer/bfbameneiokkgbdmiekhjnmfkcnldhhm)
- [ANDI Accessibility Testing Tool
](https://www.ssa.gov/accessibility/andi/help/install.html)

A11y Info:

- [WCAG Standard Guidelines
](https://www.w3.org/WAI/standards-guidelines/wcag/)
- [A11y Project
](https://www.a11yproject.com/)