drgullin / icheck

Highly customizable checkboxes and radio buttons (jQuery & Zepto)
http://fronteed.com/iCheck
7.39k stars 1.63k forks source link

Tab focus issue #292

Open keshava-v opened 8 years ago

keshava-v commented 8 years ago

when i press tab its not focusing properly .. Any solution for this

MrGorki commented 8 years ago

+1

pure180 commented 7 years ago

This issue is pretty old, but tabindex still doesn't seem to work. This is my solution using jQuery:

<label>
   <input type="checkbox" name="name" value="off" tabindex="-1" />
   Label text.
</label>
$(document).on('ready', function() {
  var checkBox = '[type="checkbox"]';
  checkBox.iCheck();
  checkBox.each(function() {
      var _this = $(this);
      var parent = _this.parent();
      parent.attr('tabindex', 0);
      parent.on('focus', function() {
         $(this).one('keydown', function(e) {
           var space = e.keyCode === 32 || e.which === 32 || e.key === ' ';
           var enter = e.keyCode === 13 || e.which === 13 || e.key === 'Enter';
           if (space || enter) {
             _this.iCheck('toggle');
           }
         });
      });
    });
});