Table sorting accessibility for AngularJS table/list

Has your SPA accessibility compliance done ?
Ahhh … let me get back to you.

That’s usual scenario for dynamic single page application. Since content of the web app changes dynamically/asynchronously. It required need addition planning to make dynamic web accessibility complain. For those who are new to web accessibility

The power of the Web is in its universality. Access by everyone
regardless of disability is an essential aspect.

There are many tools are being provided to make the web accessible like screen reader. The screen reader read out the html content with help of aria attributes. One of the accessibility attribute is aria-sort . It let the user know that the given html table is sorted by of the its column and in which order. The sorted column of the table expected to have ng-aria=”ascending/descending”.

The problem with SPA table is that on sorting the table the content get sorted without loading the web, so having static aria-sort attribute is going to help. The aria-sort attribute should get updated as the user interact with html table.

To solve this problem I have come up with angular directive to add/update aria-sort attribute dynamically to table header.

var ngAria = angular.module("NGAria", []);

ngAria.directive('ngAriaSort', function(){
  return {
      restrict:'A',
      scope:{
        orderBy : "="
      },
      link: function(scope, element, attrs, ctrl){
        if(attrs.ngAriaSort) {
          try {
            var currentCol = attrs.ngAriaSort;
            updateAriaAttribute();
            scope.$watch('orderBy', function(newVal, oldVal){
              updateAriaAttribute(); 
            },true);
          } catch(e) {
            console.warn('Error while paring sn-aria-sort attribute value : ' + e.toString());
          }

        }

        function updateAriaAttribute() {
          var isSorted = scope.orderBy.col == currentCol;
          var desc = scope.orderBy.desc;
          if(isSorted)
            element.attr('aria-sort',desc?"descending":"ascending");
          else
            element.removeAttr('aria-sort');
        }

      }
    }
});

Here is how this directive is being used

<thead>
      <tr>
        <th ng-repeat="col in cols" ng-aria-sort="{{col.name}}" order-by="orderBy">

It adds/updates the aria-sort attribute based on the current column by which the table is sorted as well as the sorting order.

Code Link is here

Also found my source repository

Comments


  1. It is a great post. Thanks for sharing such kind of noteworthy posts. Keep updating.
    AngularJS Training in Chennai | AngularJS Training Institute in Chennai

    ReplyDelete
  2. It is an awesome post. A debt of gratitude is in order for sharing such sort of important posts. Continue refreshing.
    Education | English Labs | MBA Talks | Technology

    ReplyDelete
  3. Thanks for sharing such a useful information. It is really impressive and useful. I like your blog and suggested to my friends too. Keep sharing. If anyone wants to learn Angular JS course online, please visit below site:
    angular js Online Training | angular js course | angular js online training in kurnool | angular js online training in hyderabad | angular js online training in bangalore | online courses | online learning | online education | trending courses | best career courses

    ReplyDelete
  4. It is a great article for AngularJS. Thanks for sharing this useful information.
    AngularJS Training in Chennai | AngularJS Course in Chennai | AngularJS Training Institute in Chennai

    ReplyDelete
  5. This article is very much helpful and i hope this will be an useful information for the
    needed one. Keep on updating these kinds of informative things...

    englishlabs
    Technology

    ReplyDelete
  6. It’s always so sweet and also full of a lot of fun for me personally and my office colleagues to search your blog a minimum of thrice in a week to see the new guidance you have got.

    Best PHP Training Institute in Chennai|PHP Course in chennai
    Best .Net Training Institute in Chennai
    Dotnet Training in Chennai
    Dotnet Training in Chennai

    ReplyDelete


  7. Hii sir,

    Maine aapki website dekhi joki bhut hi kamaal ki hai aur aapki sabhi jankari kafi achi hai.

    Mai bhi  likhta hun aur meri site abhi grow kr rhi hai

    Aur mai chahta hun ki aap mere sath Do-Follow backlink Exchang kare taki hmare Site ki DA badhe



    Par mai apko btana chahta hun ki Mera to fayada hoga hin isme koi shaq nhi hai par aapko bhi ek Do Follow back link milega joki apke website ke liye ek Positive Signal hoga 

     

    Aapka Busy time dene ke liye thankyou 

    Regards -Love U Nature

    Website : https://loveyounature.blogspot.com/

    ReplyDelete
  8. The information that you have shared is really useful for everyone.
    Data Science Online Training
    Python Online Training

    ReplyDelete
  9. I am reading the whole article it is very useful and there is a lot to learn. I bookmarked your blog. Waiting for the next post. Know about new technology visit our website Top 10 in history

    ReplyDelete
  10. Exceptional Blog! Generally I don’t read post on blogs, but I wish to say that this write-up very compelled me to try and do so! Your writing style has been surprised me. Thanks, very nice post. Regards :Create Sankey Diagram. Look at my articles and share your feedback : Read more here.

    ReplyDelete
  11. Good day. I was impressed with your article. Keep it up . You can also visit my site if you have time. Thank you and Bless you always.
    outsource Angularjs Application Development in India

    ReplyDelete
  12. At the point when one purchases any singular Office applications or a one-time buy Office, then, at that point, he/she can get a free item key to introduce the Office. Office Product Key Free

    ReplyDelete
  13. It took me a while to get over all the explanations, but I actually enjoyed the article. It turned out much more favorably for me and I am decided by all the commenters here! Always available from now on, you are not knowledgeable but have fun! Mixed In Key Crack

    ReplyDelete
  14. Your hard work is great, and I'm glad you shared it with me.
    Color Finale Pro

    ReplyDelete

  15. Enroll in our dynamic web designing training! Learn HTML, CSS, JavaScript, responsive design, UI/UX principles, and popular design tools. Gain practical experience through projects and mentorship from industry experts. Launch your career in web design with confidence and creativity!

    ReplyDelete

Post a Comment

Popular posts from this blog

State Design Pattern by Example

Eclipse command framework core expression: Property tester

Composite Design Pattern by example