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

Action to toggle the state of a checkbox #35794

Closed
anrghg opened this issue Aug 25, 2021 · 0 comments · Fixed by #35795
Closed

Action to toggle the state of a checkbox #35794

anrghg opened this issue Aug 25, 2021 · 0 comments · Fixed by #35795

Comments

@anrghg
Copy link
Contributor

anrghg commented Aug 25, 2021

Description

Instead of adding or removing a class, the checked state of the referenced element is toggled, or set to a predefined boolean if the optional force argument is provided.

The target usage are HTML toggles for CSS rules: A checkbox controls the styles in an adjacent sibling div. Best practice, though not mainstream due to JS prevalence.

We need the toggleChecked() action as using <label> would prevent propagating the click to an enclosing anchor, and conversely we cannot check a box when tapping on a nested anchor element.

Alternatives Considered

The toggleClass() action as a workaround fails when JS is turned off. The checkbox cannot be nested in <noscript> as this disrupts the adjacent sibling combinator. Also, noscript elements are typically repurposed in AMP environments to provide a fallback experience regardless whether JS is actually turned off.

Additional Context

https://wordpress.org/plugins/anrghg/

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.

1 participant