I have this issue. I am using a few buttons as toggle switches for selecting and unselecting checkboxes in a friendly way. Works great on desktop, but on my android (haven't tested iPhone yet) the buttons remain 'focused' until you click something else which screws with my user experience big-time.
I've read a lot about this issue but I have yet to find a solution and thought I'd ask my own question.
EDITED HTML:
<div class="service-option">
<input type="checkbox">
<button class="btn btn-sm btn-outline-secondary service-option" type="button">
Option One
</button>
</div>
<div class="service-option">
<input type="checkbox">
<button class="btn btn-sm btn-outline-secondary service-option" type="button">
Option Two
</button>
</div>
And my jQuery that just marks the button's checkbox as checked (and hides it from the user) and toggles it to be btn-secondary instead of btn-outline-secondary for visuals.
EDITED JQUERY:
$('.service-option').find('input[type=checkbox]').css("display", "none");
$('.service-option button').click(function() {
$(this).toggleClass('btn-secondary').toggleClass('btn-outline-secondary');
var checkbox = $(this).parent().find('input[type=checkbox]');
checkbox.prop("checked", !checkbox.prop("checked"));
});
I have tried a lot of different things including .blur() inside that click function but that didn't work either. On mobile devices, it just stays in a state of "greyish background" until I click elsewhere on the screen and that makes it appear to the user that they have not unselected the button when in fact it did...
Was reading here but maybe I missed something: How to stop buttons from staying depressed with Bootstrap 3
inputwithinbuttonis invalid.inputattributemultipleis invalid. You have to fix these first. - Kosh:multiple => trueis being used for my rails application where this HTML is being generated to enable multiple checkboxes to be selected to my knowledge. - Taylor A. Leach