drgullin / icheck

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

Radio is checked on focus in iCheck v2.0 #327

Open brandoski opened 8 years ago

brandoski commented 8 years ago

This apparently is a resolved issue in v1 but not in v2.0. Reference: Issue #168

When tabbing to a radio button, the focused radio button gets selected for no apparent reason.

From a user perspective, this behavior is a bit confusing, because jumping from a textbox to a radio button marks the latter as selected.

Does anyone have solution for this in v2.0?

JayAdra commented 8 years ago

+1

ghost commented 8 years ago

+1

neskhodovskiy commented 8 years ago

+1

shainanigans commented 8 years ago

+1

bkrypt commented 8 years ago

+1

Disclaimer: It's quite late here, 00h50, so whether this fix has any major implications down the line, I'll probably only find out on Monday when I work with this project again.

From what I can tell, line 946: if (self.type == 'checkbox' && event.keyCode == 32 && settings.keydown || self.type == 'radio' && !self.checked) { has a logic error. In that || self.type == 'radio' is going to cause that toggle operator function to fire no matter what whenever the element is a type 'radio'. It would also happen when any keyup event occurs actually, not just tab. It's just a little difficult to trigger any other keyup on the radio element though. ;)

The fix for me was to change that line to this rather: if ((self.type == 'checkbox' || self.type == 'radio') && event.keyCode == 32 && settings.keydown && !self.checked) {

This prevents the radio button being selected during tab movements, but keeps the ability to use space and the regular arrow keys to trigger a select of the radio element.

NewJenk commented 5 years ago

I'm looking to extend this to allow arrow keys to traverse the radios without selecting them, any ideas on how this could be done @keith1024?