Skip to content
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

[accessibility] Button plugin doesn't apply "checked"-property to checkbox/radio button when activated with the keyboard #18874

Closed
Lausselloic opened this issue Jan 13, 2016 · 13 comments

Comments

@Lausselloic
Copy link
Contributor

I've seen the #18866 and I agree.
But when the user interact with the keyboard (tab to navigate, space bar to check/uncheck) the checked property don't be updated onto radio and checkboxes.
http://v4-alpha.getbootstrap.com/components/buttons/#checkbox-and-radio-buttons

@patrickhlauke
Copy link
Member

urgh, it seems the workarounds/fixes from #16226 and #16404 may not have been ported to v4? /cc @mdo @fat @cvrebert

@cvrebert
Copy link
Collaborator

Implementing the suggestion from #17021 ought to fix this and make the plugin simpler in general:

Buttons

@cvrebert
Copy link
Collaborator

Implementation sketch of my suggestion: http://jsbin.com/lidedi/edit?html,css,output

@patrickhlauke
Copy link
Member

slightly modified/expanded (stealing some of the current buttons styles) sketch http://codepen.io/patrickhlauke/pen/PNRMve

@patrickhlauke patrickhlauke self-assigned this Apr 15, 2016
@cvrebert
Copy link
Collaborator

It might be possible, with some fiddling, to move the .btn up from the label to the .btn-checked, which might allow the .btn-group styles to "just work" (and thus let us avoid duplicating a lot of the .btn-group CSS).

@patrickhlauke
Copy link
Member

@cvrebert revisited this briefly today...something like http://codepen.io/patrickhlauke/pen/QEWRpp ? /cc @mdo

@cvrebert cvrebert added this to the v4.0.0-alpha.4 milestone May 31, 2016
@cvrebert
Copy link
Collaborator

@patrickhlauke I think the approach is good enough for a PR, so we can start nitpicking it properly 😄

@patrickhlauke
Copy link
Member

roger roger...will get onto that this week

@patrickhlauke
Copy link
Member

patrickhlauke commented May 31, 2016

@cvrebert made an attempt, but failing to get anything to work out properly with the current mixins. it also looks fairly ugly...

with a super-simplified markup of

<div class="btn-group">
  <input id="check1" type="checkbox" checked="" autocomplete="off"><label class="btn btn-primary" for="check1">Checkbox 1 (pre-checked)</label>
  <input id="check2" type="checkbox" autocomplete="off"><label class="btn btn-primary" for="check2">Checkbox 2</label>
  <input id="check3" type="checkbox" autocomplete="off"><label class="btn btn-primary" for="check3">Checkbox 3</label>
</div>

i'd conceptually would need to do something like

@mixin button-variant($color, $background, $border) {
  ...
  &:focus,
  &.focus,
  .btn-group input[type="checkbox"]:focus + label.#{&},
  .btn-group input[type="radio"]:focus + label.#{&}, {
    color: $color;
    background-color: $active-background;
        border-color: $active-border;
  }
  &:active,
  &.active,
  .open > &.dropdown-toggle,
  .btn-group input[type="checkbox"]:checked + label.#{&},
  .btn-group input[type="radio"]:checked + label.#{&} {
    color: $color;
    background-color: $active-background;
        border-color: $active-border;
    // Remove the gradient for the pressed/active state
    background-image: none;
    @include box-shadow($btn-active-box-shadow);

    &:hover,
    &:focus,
    &.focus,
    .btn-group input[type="checkbox"]:checked:focus + label.#{&},
    .btn-group input[type="radio"]:checked:focus + label.#{&},
    .btn-group input[type="checkbox"]:checked:hover + label.#{&},
    .btn-group input[type="radio"]:checked:hover + label.#{&} {
      color: $color;
      background-color: darken($background, 17%);
          border-color: darken($border, 25%);
    }
 }

but this obviously fails in Sass. not sure how to proceed without inventing completely new classes or rewriting the whole mixin approach :(

@patrickhlauke
Copy link
Member

FWIW i updated the pen http://codepen.io/patrickhlauke/pen/QEWRpp to this much simpler (from a markup and styles point of view) approach

@mdo
Copy link
Member

mdo commented Nov 27, 2016

Fixed by #18900 I believe, and same as #16673 and #17599.

@alexventuraio
Copy link

Hey there!
Has the issue being fixed? Because I still having it on Bootstrap v4.1.1. This is my example for reference.
The radio inputs do not get the checked attribute when clicking on them.

@richardebeling
Copy link

richardebeling commented Jul 2, 2018

I can also reproduce this in the bootstrap docs example, using firefox 60.0.2 and chrome 67.0.3396.99. If you click on any of the three buttons and then change your selection with the keyboard, it looks as if you've selected another button. The underlying radio input selection is not changed though. You can see this by temporarily deactivating the clip-style on the radio inputs. Running document.querySelector('input[name="options"]:checked').id; in the browser will return you the input that has the radio input selected, not the one that should be active.

Thus, if you have these buttons in a form and submit the form, the submitted value for the toggle buttons is not correct.
Am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants