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

Checkbox with data-bs-toggle: Inconsistent state on double-click or reload #35667

Closed
3 tasks done
michael-struwe-mischok opened this issue Jan 7, 2022 · 5 comments
Closed
3 tasks done

Comments

@michael-struwe-mischok
Copy link

Prerequisites

Describe the issue

Put data-bs-toggle on a checkbox like this:

           <div class="form-check">
                <input class="form-check-input" id="flexCheckDefault" type="checkbox" data-bs-toggle="collapse" data-bs-target="#collapseExample" checked>
                <label class="form-check-label" for="flexCheckDefault">
                    Default checkbox
                </label>
            </div>
            <div class="collapse" id="collapseExample">
                <div class="card card-body">
                    Some placeholder content for the collapse component. This panel is
                    hidden by default but revealed when the user activates the relevant
                    trigger.
                </div>
            </div>

Trigger the bug in one of the following two ways:

  1. Check the checkbox, then reload (tested in Firefox 95.0.1)
  2. Double-click the checkbox

Observation: It is possible to get into one of these states, and then clicking on the checkbox will toggle between them, even though both are bad states:

  • The checkbox is on, but the content is not shown
  • The checkbox is off, but the content is shown

Expected behavior: On page load and on interaction, the bad state should be detected and fixed (which combination is considered good is defined by the presence of the "checked" attribute). Or the developer experience should make it clear that this usage is not supported.

Reduced test cases

https://output.jsbin.com/lixazupoma

What operating system(s) are you seeing the problem on?

Linux

What browser(s) are you seeing the problem on?

Firefox

What version of Bootstrap are you using?

v5.1.3

@mdo
Copy link
Member

mdo commented Feb 23, 2022

I don't think we built the collapse plugin with checks/radios in mind. Would need to hear from @twbs/js-review.

@michael-struwe-mischok
Copy link
Author

See also PR #22272 ; as far as I understand it was done with the explicit intent to support the combination of checkbox/radio + collapse.

@ffoodd
Copy link
Member

ffoodd commented Feb 24, 2022

I think this was dropped for accessibility reasons: a checkbox has its own role and state, thus cannot convey role ans states needed for the collapse component.

This is not something we should handle, IMHO.

@mdo
Copy link
Member

mdo commented Apr 12, 2022

Closing per above comment.

@mdo mdo closed this as completed Apr 12, 2022
@michael-struwe-mischok
Copy link
Author

I think the above comment only said that the correct solution for this is not to support the use-case. The issue description proposes a second solution as well:

Or the developer experience should make it clear that this usage is not supported.

For instance, #22272 could be reverted. Or in the if-case that was inserted in that PR, a console.warning(...) could be emitted.

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

No branches or pull requests

3 participants