Coder Social home page Coder Social logo

accessible-chat's Introduction

Accessible chat

Accessible chat example using NodeJs, Socket.IO and Express. Which's logic can be applied to any dynamic chat.

Testing the chat

Locally

$ git clone [email protected]:Riku-E/accessible-chat.git
$ cd accessible-chat
$ npm install
$ node index.js

On the web

I have this example running on free dyno at Heroku. Might be slow from time to time if the dyno is sleeping upon connection / down if I reach the maximum up time for the free dyno. https://accessible-chat.herokuapp.com/

Problem

You might've heard about amazing role called "log" and attribute aria-atomic. https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_log_role is a really nice example of how to use it.

In perfect world, this example would be just what you need for chat application. It would alert users using assistive technologies about new messages and ingore the old ones.

<div id="chatArea" role="log">
  <ul id="chatRegion" aria-live="polite" aria-atomic="false">
    <li>Please choose a user name to begin using AJAX Chat.</li>
  </ul>
  <ul id="userListRegion" aria-live="off" aria-relevant="additions removals text">
  </ul>
</div>

Unfortunately this does not work, everytime you append elements to elements with role log Assistive Technologies will read everything out loud for you. Meaning long chat history, would always be read out loud to the users from the beggining of time.

This is not suitable solution.

Solution

I started to test and look into possible solutions to fix this issue. What I came up with, is that I do not try to use these fancy, poorly supported tags, yet.

My HTML mark-up for chat history wrapper is very simple and straight forward;

<div id="chat-history" aria-label="Chat history">
    <ul class="messages">
    </ul>
</div>

Each message creates HTML such as;

<li aria-live="polite" class="message">
  <span aria-hidden="true" class="username">Chat bot:</span>
  <span aria-hidden="true" class="message-body">Make link text meaningful</span>
  <!-- This is only appended after 250ms timeout -->
  <span class="is-vishidden">Chat bot: Make link text meaningful</span>
</li>

Why do I have 3 spans, you might ask. I could have done this with 1 span of course. I wanted to demonstrate situation where you want to highlight some elements on the history for example here I highlight the names with random colors.

To avoid screenreaders reading one element at the time I create element with only text for screenreaders and hide the visual elements from them.

On the JavaScript side, I first append the visual structure to the chat history without the is-vishidden element. Then I timeout 250ms to put the screenreader append function to the bottom of the stack. Also the timeout gives screenreaders time to recognize the new polite live region on the website.

addMessageElement($messageDiv, options);
setTimeout(function() {
  $messageDiv.append($screenReader);
}, 250);

About me

Hi my name is Riku and I have heart set on creating accessible solutions. I love to solve accessibility issues of complex designs & functionalities. Accessibility is not a barrier to innovation.

More about me at https://www.linkedin.com/in/rikuetelaniemi

accessible-chat's People

Stargazers

Tassoman avatar

Watchers

James Cloos avatar

accessible-chat's Issues

not really an issue, but a question

Came across your code as I was searching for a solution for something and I wonder if you experienced this issue as well.
I noticed this, if I have a div set like this:
role="status" aria-live="polite" aria-atomic="false"
If I put some text in there and it is reading it, and I append more text before the reader has finished speaking it, it stops where it is at and just reads the new text. It would be ideal if it kept on reading and finished reading what it was doing and then read the additional text I appended to the field.
Did you come across that? Just glancing at your stuff I noticed a timer function, that seemed to delay message posting, perhaps that was your solution?

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.