Skip to content

Radio buttons: .btn-group-toggle: Keyboard selection only works visually. #26855

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

Closed
richardebeling opened this issue Jul 11, 2018 · 9 comments
Closed

Comments

@richardebeling
Copy link

richardebeling commented Jul 11, 2018

In a toggle button group, if you select a button using the keyboard, the underlying selection of the radio inputs is not changed. Thus, if you have these buttons in a form and submit the form, the user might submit an unintended selection.

I guess this is related to #18874. I added a comment there, but there was no reaction.
#25122 and #26778 are possibly related but no duplicates imo.

Steps to reproduce:

  • In a toggle button group, click on one button with the mouse
  • Then, change your selection with the arrow keys (left / right)

Expected Result:

The radio input that represents the now selected button is checked

Actual Result:

The radio input selection is not changed although the visuals indicate that it was changed. (tested in firefox 60.0.2, firefox 61.0.1 and chrome 67.0.3396.99)

Example Code

You can reproduce the issue here. The html code is copied from the docs. I only added css to remove the clip property on the inputs so you can see which input is selected.

@Johann-S
Copy link
Member

you're right it seems the normal behavior of a radio button 🤔

/CC @patrickhlauke

@RinkAttendant6
Copy link

I can reproduce this as well on Firefox 61 and Edge 17.17134

However it seems to work perfectly fine in IE 11 🤔

@nathan-charrois
Copy link

Can confirm this is an issue in Firefox 64, and Chrome 71, Safari 12.0

@richardebeling
Copy link
Author

If someone comes by here and is searching for a solution: This is the work around we came up with: https://github.com/fsr-de/EvaP/pull/1326/files

$(document).on("click", '[data-toggle^="button"] input[type="radio"]', function(event) {
  // Bootstrap will call event.preventDefault() which results into a reset of the radio buttons before the keyboard input.
  // To work around this, we set the method to one without side effects.
  event.preventDefault = () => true;
});

@Lausselloic
Copy link
Contributor

Fix is in progress for V4 and V5 thanks to @patrickhlauke
#28565

@patrickhlauke
Copy link
Member

patrickhlauke commented Apr 2, 2019

[deleted comment, as it was in the wrong thread]

@patrickhlauke
Copy link
Member

sorry, late reply...fixed with this, i believe #28834

@LinqLover
Copy link

Are you really sure this has been fixed in v4? For me, the radio group example from the docs still does not register the selection in the model if I use arrow keys ...

@patrickhlauke
Copy link
Member

there were further changes that broke it apparently, but then further fixes after that. in the end the complete fix came in 4.4 https://getbootstrap.com/docs/4.4/components/buttons/#checkbox-and-radio-buttons

in general, suggest updating to the latest version

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

Successfully merging a pull request may close this issue.

7 participants