-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix radio button toggle behavior for keyboard users #16226
Fix radio button toggle behavior for keyboard users #16226
Conversation
Tests passed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: CONFIRMED Commit: f6531aa (Please note that this is a fully automated comment.) |
This needs a unit test. |
Also, is there a reason the condition isn't |
Not sure how to unit test "if a radio button has been chosen via the keyboard", and not quite sure what to actually test for...thoughts? As for |
Tests passed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: CONFIRMED Commit: 3c8977f (Please note that this is a fully automated comment.) |
@cvrebert any idea/pointer for how this could be unit-tested? simulate actual keyboard interactions somehow? |
This doesn't actually seem to fix anything: Demo: http://jsfiddle.net/oxnksxaj/ |
@@ -107,7 +107,7 @@ | |||
var $btn = $(e.target) | |||
if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure your check needs to happen before this line; otherwise, $btn
will always be the label.btn
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, absolutely right. amended below by referencing e.target
instead
Tests passed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: CONFIRMED Commit: 613eedd (Please note that this is a fully automated comment.) |
@cvrebert not sure what the heck i did there...i could have sworn it worked (but then i did mess around with the JS/test a bit too much and probably lost track at some point of what i was doing). Fixed, i think...see http://jsfiddle.net/vjjmj4da/1/ |
@patrickhlauke Okay, but now it suffers from the "double |
Regarding testing this, FWICT, the relevant difference between mouse and keyboard is that keyboard usage results in click events fired at the invisible |
for the double
from cursory testing, this now seems to correctly address mouse and keyboard usage, unless i've missed something. thanks for the info on testing. will have a go at making some tests later too. |
@@ -56,8 +56,8 @@ | |||
if ($parent.length) { | |||
var $input = this.$element.find('input') | |||
if ($input.prop('type') == 'radio') { | |||
if ($input.prop('checked') && this.$element.hasClass('active')) changed = false | |||
else $parent.find('.active').removeClass('active') | |||
if ($input.prop('checked')) changed = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indented one level too much
as this breaks keyboard navigation for radio button toggles (see #16223)
Tests passed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: CONFIRMED Commit: 66d7113 (Please note that this is a fully automated comment.) |
Unfortunately, this doesn't seem to be the case - even testing the case that is currently broken for keyboard users http://jsfiddle.net/oxnksxaj/ and explictly doing something like
in the console does check the radio button correctly, which is not the case for actual keyboard use. I might be wrong, but I can't see any immediate way to test/simulate keyboard interaction in this case? |
Fix radio button toggle behavior for keyboard users
As I haven't heard anything to the contrary, merged. If the absence of a unit test (which seems elusive, as the behavior seems to depend on actual browser interaction, which can't be tested in a straightforward way in a headless engine-only setup it seems) is a problem, I'd say let's revisit that aspect separately. |
👍 for this issue I've managed to replicate the issue here http://codepen.io/anon/pen/MwwyRW |
I don't think this actually fixes it as now we have the issue that the focus still displays which is now even more confusing for the user. |
From what I can see the one line the other changes break the active class. Also adding See the working fixes here: http://codepen.io/anon/pen/vOOKNj Here's a quick diff: https://www.diffchecker.com/ogg8uuer |
Your 1st codepen uses v3.3.4's JS; the fix is in |
@cvrebert Is there a link to a master? As I don't believe this will actually fix it. |
@cvrebert As I mentioned these changes have broken it even further http://codepen.io/anon/pen/waaWGZ I can't even get it to work onClick now. Note: this is running on |
@alexw23 your pen isn't working because of rawgithub From the Chrome DevTools console: "Refused to execute script from 'https://raw.githubusercontent.com/twbs/bootstrap/master/dist/js/bootstrap.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled. |
However, I can see what you mean now about the class not being set once moving focus off the radio buttons (just brutally forked you pen and slammed bootstrap.js into the JS part) http://codepen.io/patrickhlauke/pen/zGGKwJ |
(FYI: rawgit.com serves the raw GitHub files with the proper headers.) |
That seemed to be the issue I've updated the codepen. http://codepen.io/anon/pen/waaWGZ However this doesn't work for enter key (for the first tab) |
Note that, by default (talking native standard browser behavior here, without any Bootstrap) radio buttons don't really react to ENTER. Instead, if focusing on the first of a group of unselected radio buttons, you'd use SPACE to toggle it. |
Okay well I guess it's fixed then sorry for the confusion. On Fri, May 1, 2015 at 8:02 AM, Patrick H. Lauke [email protected]
|
No need to apologize, and nope not quite fixed yet...seems the |
My diff fixes this however http://codepen.io/anon/pen/vOOKNj I guess you could remove the |
But your diff seems to suffer from the same problem I bumped againsts: I think I managed to simplify the existing code and avoid any major pitfalls... http://codepen.io/patrickhlauke/pen/zGGEEY |
@patrickhlauke seems like it fixes, finally! tried on chrome & firefox on linux. |
Just to be a pain we should look at replicating checkbox functionality also... I've added non-bootstrap radio/checkboxes for reference as to the normal usability. http://codepen.io/anon/pen/eNNGjO
|
More hacking around, seems to work now for checkboxes too (but the code is slowly getting a bit fugly, will need some cleaning up/reworking I think) http://codepen.io/patrickhlauke/pen/OVVOGL |
as this breaks keyboard navigation for radio button toggles - fixes #16223