Coder Social home page Coder Social logo

a11y support about react-retro-hit-counter HOT 2 OPEN

joshwcomeau avatar joshwcomeau commented on August 15, 2024
a11y support

from react-retro-hit-counter.

Comments (2)

joshwcomeau avatar joshwcomeau commented on August 15, 2024 1

Oh wow, awesome. Thanks so much for this trove of info!

Sounds pretty straightforward, and about what I expected. While in my own projects I haven't made the counter update after initial render, presumably others who use this project might!

Live regions seem really neat! This counter is just presentational, so presumably some folks might want to have it auto-update? I think I'll wait and see if this counter is used anywhere outside my own projects (which don't auto-update).

Thanks again for the info :)

from react-retro-hit-counter.

stephenbelyea avatar stephenbelyea commented on August 15, 2024

First of all, awesome to see you're thinking a11y @joshwcomeau!

Since the React Retro Hit Counter is intentionally presentational, with no user action expected, your work for serving a readable version for assistive tech can be pretty simple.

For a good, solid start, you'll want to have a textual version of the counter value available in the DOM. This could be as simple as a <p>1234</p> somewhere in your main wrapper. Though, I would definitely suggest a little more context - something like <p>This site has had 1234 visitors!</p> - to round out the cues that sighted users would grok automatically.

To visually hide the alternative text, you can use a similar approach to Bootstrap's .sr-only class, meant to retain the text as machine-readable. Something like this (grabbed from this handy post on the subject):

.screen-reader-only {
   position: absolute;
   height: 1px;
   width: 1px;
   clip: rect(1px 1px 1px 1px); // IE 6 and 7
   clip: rect(1px,1px,1px,1px);
   clip-path: polygon(0px 0px, 0px 0px, 0px 0px);
   -webkit-clip-path: polygon(0px 0px, 0px 0px, 0px 0px);
   overflow: hidden !important;
 }

Since the counter itself provides no content for non-sighted users and machines, I would even consider employing aria-hidden on a wrapper (that doesn't include the text element) to ensure that screen readers that follow the ARIA spec will skip it entirely. Something like this:

<div>
  <p class="screen-reader-only">This site may or may not have had 1234 visitors!</p>
  <div aria-hidden="true">...</div>
  <canvas aria-hidden="true">...</canvas>
</div>

If you're looking to mod the counter to change it's value while it is mounted (eg. syncing ongoing traffic while a user is mid-session), you could get into some fun with ARIA's live region options as well.

from react-retro-hit-counter.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.