DEV Community

Antonin J. (they/them)
Antonin J. (they/them)

Posted on

2

Accessibility labels for content loading in React

I've really been enjoying learning about how to make applications and websites more accessible and recently wondered about how to appropriately label a loader for a side project React app I'm writing. After scouring Stackoverflow answers, and looking at what Bootstrap's solution is, I came across an article by some company called Dockyard. They all conflict in different ways. Finally, I followed an SO link to Fundamental UI. And came up with this idea:

const Loader = () => <div aria-label="Loading">loading...</div>;

const LoadContent = ({ isLoading, children }) => {
  return (
    <div aria-busy={isLoading} aria-live="polite">
      {isLoading && <Loader />}
      {!isLoading && children}
    </div>
  );
};
Enter fullscreen mode Exit fullscreen mode

Here's what it does (as I understand it):

  • aria-busy lets us indicate that the container is in the process of updating.
  • aria-live lets us indicate that the element is going to updated. The polite property indicates a background change (this might be a good place to add a prop to indicate if the content is main content, or background content)
  • aria-label lets us indicate the label for the element.

I made a Sandbox where you can check this out in action.

I'm still getting started with accessibility so I welcome any input on this.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay