Skip to content

Toggle buttons don't honor [disabled] or .disabled #21237

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
toby-howell opened this issue Nov 28, 2016 · 6 comments
Closed

Toggle buttons don't honor [disabled] or .disabled #21237

toby-howell opened this issue Nov 28, 2016 · 6 comments

Comments

@toby-howell
Copy link

toby-howell commented Nov 28, 2016

There doesn't appear to be a clean way to disable a button state toggler. I've tried the following:

<div class="btn-group disabled" data-toggle="buttons" aria-disabled="true" disabled>
    <label class="btn btn-danger disabled" aria-disabled="true" disabled>
        <input type="checkbox" aria-disabled="true" autocomplete="off" disabled class="disabled"/>
        Click me a few times
    </label>
</div>

This button appears disabled but .active is added/removed when it is clicked and the checkbox's checked state is toggled.

I have worked around this by listening for the click event and cancelling it if the <input> is disabled, but I hoped that there would be a nicer way to accomplish this. If this behaviour is not a bug, consider this to be a feature request.

The .btn-danger in the above test case exhibits the behaviour described. The .btn-success is an example of the currently necessary workaround.

This was encountered in Bootstrap v4.0.0-alpha.5.

@cvrebert
Copy link
Collaborator

X-Ref: #18874 (comment)
Using a pure-CSS approach would address this problem (a user cannot click/check a [disabled] <input type=checkbox>).

@cvrebert cvrebert changed the title Allow button state toggling to be disabled Toggle buttons don't honor [disabled] or .disabled Nov 29, 2016
@PurvaA
Copy link

PurvaA commented Nov 30, 2016

@toby-howell

This issue is fixed by adding custom code using jQuery

Please check my solution here: http://jsbin.com/xoruzeqehi/edit?css,output

I am attaching screen shot.

disabled_class

Please let me know in case of any concerns/ queries

@dcgit
Copy link

dcgit commented Dec 4, 2016

The problem appears to be related to the initial state of the hidden checkbox as the btn initalizes. When the label in your example initializes as a button control, the checkbox value is automatically set as .active and [checked], although im not sure where in the bootstrap code this happens.

A similar issue was posted and resolved 3 years ago where the inital state is not properly reflected.

@dcgit
Copy link

dcgit commented Dec 4, 2016

Also if you use a button instead of label, it appears to disable properly but the hidden checkbox still winds up with the initial state of active and checked

@dcgit
Copy link

dcgit commented Dec 4, 2016

Im wrong about the initial state. Some test code i added to your example was triggering an inital click that threw me off. I was still able to verify that if you change the label to a button it works as expected.

@mdo mdo modified the milestones: v4.0.0-alpha.6, v4.0.0-beta Jan 2, 2017
anniepank added a commit to anniepank/bootstrap that referenced this issue Apr 22, 2017
@Johann-S
Copy link
Member

PR : #22499

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